> In my application, I need a thread to wait on another
> thread to send a cond_signal. Easy enough, but if the
> second thread hasn't reached the cond_wait by the time the
> cond_signal appears, then the signal is discarded and the
> cond_wait will end up blocking forever.

You can't just rely on the locking.  You need to deal with a
flag value sent in the shared variable:

my $flag :shared = 0;

sub thr1
{
    ...
    {
        lock($flag);
        $flag++;
        cond_signal($flag);
    }
}


sub thr2
{
    ...
    {
        lock($flag);
        while(! $flag) {
            cond_wait($flag);
        }
    }
    ...
}

Hope that helps.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Reply via email to