[omniORB] Condition varaibles - follow up...

Sai-Lai Lo S.Lo@orl.co.uk
21 Jan 1999 12:25:04 +0000


Hi Ole,

I think there is some misunderstanding on how to use conditional variable.
In your code, you have never lock the mutex cond_mutex which is the mutex
that you have initialised the conditional variables empty_buf and full_buf.

Remember in your code, the conditional variables have to be initialised
with a mutex as the ctor argument. When you use wait(), it is a
pre-condition that the calling thread must hold the lock on the mutex with
which the conditional variable is held. This is how the semantics of wait()
is defined. (The wait operation may atomically **unlocks** the mutex and
blocks the thread.)

Have a look at omnithread.h for some explanation. For a tutorial on how
to use conditional variables, I think the DEC SRC report no. 35 by Andrew
Birrell "An Introduction to Programming with Threads" is the
best. (http://www.research.digital.com/SRC/home.html)

Sai-Lai

-- 
Dr. Sai-Lai Lo                          |       Research Scientist
                                        |
E-mail:         S.Lo@orl.co.uk          |       Olivetti & Oracle Research Lab
                                        |       24a Trumpington Street
Tel:            +44 223 343000          |       Cambridge CB2 1QA
Fax:            +44 223 313542          |       ENGLAND