However, that is the hard way. The cond_* functions are very low-level, and for most purposes you should use a higher-level abstraction: e.g., create a queue, and signal by pushing an item onto the queue:use strict; use warnings; # hallelujah use threads; use threads::shared; # threads, oh how I hate my $lockvar : shared = 0; my $thrHandle; { lock $lockvar; $thrHandle = threads->create( \&exampleSub ); cond_wait ($lockvar); print "parent running\n"; } $thrHandle->join(); sub exampleSub { print "child init\n"; sleep 2; print "child init finished\n"; { lock $lockvar; cond_signal($lockvar); } print "child running\n"; }
use strict; use warnings; # hallelujah use threads; use threads::shared; # threads, oh how I hate use Thread::Queue; my $q = Thread::Queue->new; my $thrHandle = threads->create( \&exampleSub ); $q->dequeue; print "parent running\n"; $thrHandle->join(); sub exampleSub { print "child init\n"; sleep 2; print "child init finished\n"; $q->enqueue(0); print "child running\n"; }
Dave
In reply to Re: Blocking cond_signal until someone cond_waits
by dave_the_m
in thread Blocking cond_signal until someone cond_waits
by bucky0
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |