in reply to threads, ->Join() and others
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;
|
|---|