Well, to use the cond_wait stuff, the parent should lock before creating the child. This will work:
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"; }
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 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.