[ECOS] Condition Variables w/o mutual exclusion?

Grant Edwards grante@visi.com
Tue Oct 2 11:39:00 GMT 2001

Hi All,

I need a mechanism for one or more threads to block until an
event happens inside a DSR.  Something like a flag bit would be
perfect, but according to the table at
condition variables are the only mechanism usable from a DSR.

Reading the section on condition variables, 

  Condition variables are a synchronization mechanism which
  (used with a mutex) grants several threads mutually exclusive
  access to shared data and to broadcast availability of that
  data to all the other threads.

But, I don't have any data to which I want to provide mutually
exclusive access.  I just want to wake up any and all threads
waiting for the event.

Is there a way to use condition variables w/o the added mutex

If I do have to use mutexes I don't need, I assume the client
threads can use the sequence below:


Reading further in the section on condition variables, it says
you should always use cyg_cond_wait() in a loop:

  The thread can only be awakened by a call to
  cyg_cond_signal() or cyg_cond_broadcast() on the same
  condition variable. When the thread is awakened, the mutex
  will be reclaimed before this function proceeds. Since it may
  have to wait for this, cyg_cond_wait() should only be used in
  a loop since the condition may become false in the meantime.
  This is shown in the following example:

What does "the condition may become false in the meantime"
mean? Specifically, to what does "the condition" refer?

This implies that the thread may be awakened spuriously when the
event it is waiting for hasn't happened, but the first sentence
says that the thread can only be awakened by a
signal/broadcast. I don't understand why the loop is required
-- under what conditions will the thread be awakened when it
shouldn't be?

Grant Edwards

More information about the Ecos-discuss mailing list