This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: condition variables and mutexes
- To: "Trenton D. Adams" <tadams at theone dot dnsalias dot com>
- Subject: Re: [ECOS] condition variables and mutexes
- From: Nick Garnett <nickg at redhat dot com>
- Date: 10 Aug 2001 16:06:02 +0100
- Cc: <ecos-discuss at sources dot redhat dot com>
- References: <001301c121ac$2276d830$090110ac@TRENT>
"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