Fri Nov 4 11:47:53 EDT 2011
Condition Variables : cyg_cond_wait()
For a brief general explanation on condition variables, see
wikipedia. The eCos implementation is quite standard. See
In general it works like this. A condition variable is protected by a
mutex to guarantee atomitcity of the variable access, and to guarantee
that a condition can be signalled inside a critical section.
WAIT() // UNLOCK, WAIT, LOCK
The WAIT() operation needs to unlock the resource before blocking to
allow senders to perform a signal.
The WHILE loop is necessary because there might be more than one
thread waiting on a condition. Even while receiving a signal (a
wake-up call) there is no guarantee about the *semantics* of the data
that is protected by the lock, because another thread might have woken
up before us and changed the data before we get woken up.
The sender side is simpler. SIGNAL or BROADCAST wake up one or more
threads that are waiting for the condition variable. It's not
necessary to do this inside the critical section, but often useful to
do so to atomically change the protected data before signalling.