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 recap



  > Gary Thomas wrote:
  > > The difference between cyg_cond_signal() and cyg_cond_broadcast()
is
  > > that with the former at most one thread waiting on the condition
  > > variable will be awakened.
  > 
  > You mean "at least", not "at most". cyg_cond_signal() may wake up
more
  > than
  > one thread (which is the norm for CV implementations, not just
eCos).
  > That's why you should always loop and retest the condition when
doing a
  > cyg_cond_wait().
  > 

Ok, I'm not sure I understand at the moment.  Maybe I'm having a bad
day, or maybe I'm just a moron.  Either way, this is what I don't
understand.

Here's some quotes from another message sent by Srinivasan Sriram titled
"CONDITION VARIABLES & MUTEXES" about a month ago.

  > > WHY DO WE REQUIRE THE WHILE LOOP? ANY WAY THE
  > > CYG_COND_WAIT CANNOT PROCEED BEFORE IT OBTAINS THE
  > > MUTEX AND BROADCAST FROM THE PRODUCER AND OTHER
  > > THREADS?
  > 
  > Two threads waiting on the condition may be woken up. They won't run
at
  > the
  > same time since only one can have the mutex locked, but when the
second
  > one
  > runs, the condition will not be true any more.
  > 

Does this mean that during cyg_cond_wait () an internal variable is set
to FALSE?  If so, then the next thread to continue inside it's
cyg_cond_wait () will simply return because the condition variable is no
longer valid?  Also, this would only happen if two or more threads
happened to be woken up at the same time right?

  > > ALSO COULD ANYONE EXPLAIN - WHAT IS THE VARIABLE IN
  > > THE WHILE LOOP. WHAT DOES IT TEST?
  > 
  > The condition you are waiting for...
  >

The condition_not_true statement must contain a variable that I make for
testing whether the loop should continue or not, and I would set this
variable to true after one of the consumer threads finished using the
resource!  Correct?  Man that had to be the longest sentence I've ever
written! :~o

  > As Robin says, you should read some general books about concurrency
  > theory.
  > There's probably stuff on the web, or I can recommend Concurrent
Systems
  > by
  > J. Bacon published by Addison Wesley.

So, if I'm not correct above, then I'll assume I don't know what the
hell I'm talking about, and I'll do as Robin says and go and read more
on the subject!  (second longest sentence I've ever written) ;)


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