bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Signalling a condition


From: Federico Montesino Pouzols
Subject: Re: Signalling a condition
Date: Mon, 6 Jan 2003 17:08:57 +0100
User-agent: Mutt/1.4i

        Hi, I guess you are considering that Conditional handles the
mutex as well as the condition variable. However, Conditional is meant
to allow the user to independently perform operantions on both
things. You may find interesting a mail in the arhives from November,
"[ Patch #623 ] ost::Conditional is broken with posix threads". There
is also a discussion on this on the savannah patch manager (you may
need to browse the 'closed' patches).

On Wed, Jan 01, 2003 at 11:08:25PM +0200, Albert Strasheim wrote:
> Hello,
> 
> I have a question about Conditional::signal().
> 
> According to the glibc manual (describing pthread_cond_wait),
> 
> "Unlocking the mutex and suspending on the condition variable is done 
> atomically. Thus, if all threads always acquire the mutex before 
> signaling the condition, this guarantees that the condition cannot be 
> signaled (and thus ignored) between the time a thread locks the mutex 
> and the time it waits on the condition variable."
> 
> The current code:
> 
> void ost::Conditional::signal(bool broadcast) 
> {
>   if(broadcast)
>     pthread_cond_broadcast(&_cond);
>   else
>     pthread_cond_signal(&_cond);
> }
> 
> But according to the glibc manual, "... if all threads always acquire 
> the mutex before signaling the condition ...".
> 
> The new signal method would then read:
> 
> void ost::Conditional::signal(bool broadcast) 
> {
>   enterMutex();
>   if(broadcast)
>     pthread_cond_broadcast(&_cond);
>   else
>     pthread_cond_signal(&_cond);
>   leaveMutex();
> }
> 
> What will happen now is that all the threads that called
> pthread_cond_wait will start waking up, and one will acquire the mutex. 
> It will then possibly do something, and then unlock the mutex and go 
> about its business, allowing the next thread to complete its
> pthread_cond_wait call and so forth.
> 
> Comments? Am I even correct? :-)
> 
> Cheers,
> 
> Albert
> 
> 
> _______________________________________________
> Bug-commoncpp mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/bug-commoncpp




reply via email to

[Prev in Thread] Current Thread [Next in Thread]