develooper Front page | perl.perl5.porters | Postings from August 2012

Re: [perl #114378] cond_signal does not wake up a thread

Thread Previous | Thread Next
Dave Mitchell
August 3, 2012 03:08
Re: [perl #114378] cond_signal does not wake up a thread
Message ID:
On Thu, Aug 02, 2012 at 10:21:24PM -0700, Matti Linnanvuori via RT wrote:
> What I meant that if Perl did not emit a warning when calling cond_signal on an unlocked 
> variable, I would not have locked the variable and so the bug would not have been written. The 
> no warnings 'threads' to avoid the warning seems such an unclean hack.

I think you misunderstand. For correct use of cond_signal, you *must* hold
the lock first(*), so perl's warning is correct. Your mistake was in not
subsequently unlocking the var.

* because otherwise you can't be sure that the other thread has yet
reached cond_wait(), so the signal could get lost and deadlock ensue.
Which is another reason why you should avoid cond_wait/signal for most
code. It's too hard to get right.

"There's something wrong with our bloody ships today, Chatfield."
    -- Admiral Beatty at the Battle of Jutland, 31st May 1916.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About