ethrbunny has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use threads; use threads::shared; my $locked : shared; lock( $locked ); print "locked(main)\n "; $thr = async{ test() }; print "starting\n"; $wait = cond_timedwait( $locked, time() + 5 ); print "result: timeout\n" if ( !defined( $wait )); print "done\n"; exit; sub test { print "started. \n"; lock( $locked ); print "locked(test)\n "; sleep( 10 ); print "exiting\n"; cond_signal( $locked ); }
If the thread sleeps for 5 and the timer waits for 10 then it seems to signal properly and exit. Its the 'stuck' case (thread sleeps for 10, timer waits for 5) that doesn't seem to work as I would expect it to.locked(main) starting started. locked(test) exiting result: timeout done
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: threads - cond_timedwait question
by Khen1950fx (Canon) on Dec 31, 2009 at 21:07 UTC | |
by ethrbunny (Monk) on Dec 31, 2009 at 22:00 UTC | |
by ethrbunny (Monk) on Dec 31, 2009 at 22:32 UTC |