This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: condition variables and mutexes


"Trenton D. Adams" <tadams@theone.dnsalias.com> writes:

> Do I have to do the "while buffer empty" part if I've only got one
> consumer thread?  Because I figured the condition variable would only
> get signaled once each round, and the buffer would never be empty except
> for when the transmit thread is waiting on the condition variable.  No?

It is not good practice to rely on the semantics of the condition
variable signal operation to always wake up exactly one waiter. We
explicitly permit condition variables to generate spurious wakeups. So
it can never be guaranteed that when a thread awakes from the wait,
that the condition is still true, it must always check the state by
independent means.

Now, you might get away with it in your case, but as a general rule,
the loop should always be used.


-- 
Nick Garnett, eCos Kernel Architect
Red Hat, Cambridge, UK


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]