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


"Trenton D. Adams" wrote:
> 
> 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?

Yes. They will all have been woken up by the broadcast, and then each go
through locking and unlocking the mutex. By that point the condition may no
longer be true of course, i.e. there may be no more waiting data. I would
imagine cyg_cond_signal() would be more appropriate (although there's still
a chance more than one thread is woken up).

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
Come to the Red Hat TechWorld open source conference in Brussels!
Keynotes, techie talks and exhibitions    http://www.redhat-techworld.com/


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