This is the mail archive of the pthreads-win32@sources.redhat.com mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: waiting for more than one cond in pThread question


On Tue, 2 Apr 2002 13:27:25 +0200, "Nir Nizry"
<nir.nizry@bluesoft-inc.com> wrote:

>I probably wasn't much understood. What I'm trying is wait for one OR more.
>I want to "be release" when either one OR more of the conds/events are set
>and I have to know which one was set.

OK, how about you associate one mutex/condvar with the _set_ of
predicate conditions[1], and do something like:

============================================================
pthread_mutex_lock(&mutex);
while (predicate_one == FALSE && predicate_two == FALSE)
{
	pthread_cond_wait(&condvar, &mutex);
}
pthread_unlock_mutex(&mutex);

if (predicate_one == TRUE)
	do_something();
else if (predicate_two == TRUE)
	do_something_else();
else
	something_horrible_happened();
============================================================

1. I'm sure the great and the good will have something to say about
the wisdom of doing this!

-- 
PGP key ID 0xEB7180EC
Available from http://www.keyserver.net


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