Re: pthread_cond_signal is mutex lock/unlock needed ?
- From: Sergei Organov <osv@xxxxxxxxx>
- Date: Mon, 18 Feb 2008 14:10:16 +0300
David Schwartz <davids@xxxxxxxxxxxxx> writes:
On Feb 14, 9:47 am, Sergei Organov <o...@xxxxxxxxx> wrote:
Provided you still change the condition itself under protection of
mutex, like this:
pthread_mutex_lock
change condition
pthread_mutex_unlock
pthread_cond_signal
you are safe. Compared to signalling with mutex locked, it could only
lead to additional spurious wakeups.
This is incorrect. You are not necessarily safe. The problem is that
the 'pthread_cond_signal' might signal a thread that blocked after the
'pthread_mutex_unlock' call rather than one that was already blocked.
Yeah, me stands corrected. I was not careful enough choosing words. What
I actually meant to say is that POSIX doesn't require mutex to be locked
in order to safely call pthread_cond_signal(). It's indeed not
necessarily safe from the POV of particular application logic. Though to
be picky, I can argue that calling pthread_cond_signal() with mutex
locked is not necessarily safe either ;)
-- Sergei.
.
- References:
- Re: pthread_cond_signal is mutex lock/unlock needed ?
- From: Sergei Organov
- Re: pthread_cond_signal is mutex lock/unlock needed ?
- From: David Schwartz
- Re: pthread_cond_signal is mutex lock/unlock needed ?
- Prev by Date: Re: portable application
- Next by Date: Re: How to wait for multiple threads simultaneously?
- Previous by thread: Re: pthread_cond_signal is mutex lock/unlock needed ?
- Next by thread: how to recovry /dev/null
- Index(es):
Relevant Pages
|