Can you suggest a more inteligent way to prevent the main thread from finishing. Thanks in advance.use threads; use Thread::Semaphore; my $semaphore = Thread::Semaphore->new(4); # max number of proccesors + to use for $i (1..10) { my $thr = threads->new(\&sub1, $i); $thr->detach(); } sleep 20; sub sub1 { $semaphore->down(1); $tn = shift; print "thread $tn is working\n"; $s = int(rand 4) +1; # a long calculation sleep $s; $semaphore->up(1); }
In reply to Re^2: Thread detach
by ilanv
in thread Thread detach
by ilanv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |