in reply to Re: Thread detach
in thread Thread detach
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); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Thread detach
by BrowserUk (Patriarch) on Jan 24, 2005 at 23:37 UTC |