in reply to threads - cond_timedwait question
#!/usr/bin/perl - use strict; use warnings; use threads; use threads::shared; my $locked :shared; lock($locked); print "locked(main)\n "; my $thr = async( sub { test() } ); print "starting\n"; my $wait = time() + 15; until ( my $ok = lock($locked) ) { last if !cond_timedwait( $locked, $wait ); } print "result: timeout\n" if defined $wait; print "done\n"; exit; sub test { print "started. \n"; lock($locked); print "lock(test)\n "; sleep 10; print "exiting\n"; { no warnings 'threads'; cond_signal($locked); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: threads - cond_timedwait question
by ethrbunny (Monk) on Dec 31, 2009 at 22:00 UTC | |
by ethrbunny (Monk) on Dec 31, 2009 at 22:32 UTC |