Re: pthread_cond_signal is mutex lock/unlock needed ?
- From: Sergei Organov <osv@xxxxxxxxx>
- Date: Thu, 14 Feb 2008 20:47:13 +0300
cached byte <jo0x000001a@xxxxxxxxx> writes:
Hi
I want to know if i always need to use the pthread_cond_signal in an
mutex lock / unlock sequence , or can i safely use the
pthread_cond_signal on its own ?
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.
On the other hand, the above sequence could be much more efficient than
signalling with mutex locked provided pthread implementation doesn't
implement so called "wait morphing", especially if you use
pthread_cond_broadcast instead of pthread_cond_signal.
-- Sergei.
.
- Follow-Ups:
- 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: pthread_cond_signal is mutex lock/unlock needed ?
- 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: Re: pthread_cond_signal is mutex lock/unlock needed ?
- Index(es):
Relevant Pages
|