Posted on 2010-07-31 08:43:54.483125-07 by patha in response to 12858
Re: block until one thread is joinable?
This is perhaps better code (replacing select_one_to_join and join_some):
sub join_any () { for (;;sleep(0.01)) { my @thrs = threads->list(threads::joinable); return $thrs[0]->join() if (@thrs > 0) } } sub limit_threads ($) { my ($limit) = @_; for (; threads->list() > $limit; ) { handle_result(join_any()); } }
Direct Responses: 12860 | Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.