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]

Condition Variables w/o mutual exclusion?


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
http://sources.redhat.com/ecos/docs-latest/ref/ecos-ref.13.html#pgfId=1080419
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
overhead?

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

  cyg_cond_wait(foo_cond);
  cyg_mutex_unlock(foo_mutex);

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
grante@visi.com


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