Re: [PATCH] threaded pack-objects: Use condition variables for thread communication.
- From
Johannes Sixt <johannes.sixt@telecom.at>
- Date
- Dec 16, 2007, 18:41 UTC
- Message-ID
- <200712161941.38109.johannes.sixt@telecom.at>
- In-Reply-To
- <20071216120558.GA4999@xp.machine.xx>
On Sunday 16 December 2007 13:05, Peter Baumann wrote:
Show 9 quoted lines
> On Sun, Dec 16, 2007 at 12:18:53AM +0100, Johannes Sixt wrote: > > + > > + progress_lock(); > > + me->working = 0; > > + progress_unlock(); > > + pthread_cond_signal(&progress_cond); > > Shouldn't the pthread_cond_signal be inside the lock? > e.g. swap progress_unlock() with pthread_cond_signal(&progress_cond)
No, that's not necessary. Both ways are correct, but if it's outside the lock there is less contention on the mutex (because the waiting thread must acquire the mutex lock before it can return from pthread_cond_wait).
-- Hannes