I am not aware of any cross-platform way to set thread priority. However you can limit the number of threads you create by simply checking how many threads you get from threads->list and waiting to spawn a new thread until scalar(threads->list) < $max_threads.
Something like:
use threads; my $max_threads = 5; for( 1..20 ) { sleep(1) until scalar(threads->list) < $max_threads; threads->create( \&do_work ); } # Now wait for the remaining threads to finish: $_->join foreach threads->list;
In reply to Re: threads, ->Join() and others
by jdrago_999
in thread threads, ->Join() and others
by Steve_BZ
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |