Path: secnews.netscape.com!rls@netscape.com
From: Rob McCool 
Newsgroups: netscape.devs-nsapi
Subject: Re: Condition Variables are Worthless, show me why they aren't
Date: Thu, 19 Dec 1996 13:29:46 -0800

Gary Gies wrote:
> 
> As far as I can tell, Netscapes condition variables are worthless.
> 
> Could somebody give me a code example of how a condition variable can be
> used by multiple threads in a producer-consumer relationship.
> 
> i.e. The consumer wakes up when there is something to consume.
> 
> According to the Enterprise Server Programmers Guide, the only way to
> wait for a condition variable is using
> 
> crit_enter(c);
> condvar_wait(cv);
> crit_exit(c);
> 
> The only way to notify is:
> 
> crit_enter(c);
> condvar_notify(cv);
> crit_exit(c);
> 
> Since each has to enter the critical section, if the waiter is already
> in the critical section, then they will never wake up since the notifier
> cant enter.

A common misconception about condvar_wait() is that the critical section 
is held for the entire time that a thread is in that function. It isn't.
When a thread enters condvar_wait, it releases the critical section and 
begins waiting. When it is notified, it reacquires the critical section
before leaving condvar_wait().

--
Rob McCool, robm@netscape.com http://home.netscape.com/people/robm/
Stunt Programmer, Netscape Communications Corporation
It was working ten minutes ago, I swear...
Reproduced by permission of the author.