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 recap


Ok, below I describe condition variables as far as I know them.  I'm not
actually using them yet, I'm just preparing to use them.  Please tell me
if I'm wrong somewhere.  If I'm not wrong, a simple "Sounds good" will
be sufficient! :)

Main Program
I initialize the condition variable and corresponding mutex before
starting my threads.

Producer Thread
I lock the mutex in my producer thread before starting or resuming the
consumer threads.
When data is ready, I call cyg_cond_broadcast ().

Consumer Thread
Each consumer thread starts in a loop and checks the condition variable
by calling cyg_cond_wait ().
They will either be suspended, or one will succeed.
After the producer thread calls cyg_cond_broadcast (), ONE consumer
thread will lock the mutex, and begin reading data.
Now this thread should call cyg_mutex_unlock () which will cause another
ONE thread to lock it.


Now I have a question.  What happens to the cyg_cond_wait () call in the
OTHER consumer threads when cyg_cond_broadcast () is called?  Do they
simply get suspended, after that other ONE consumer thread locks the
mutex, and until the mutex is available to ONE of them again?

Trenton D. Adams
Embedded Developer
Windows Developer
Extreme Engineering Ltd.
Calgary Alberta.




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