This is the mail archive of the
pthreads-win32@sources.redhat.com
mailing list for the pthreas-win32 project.
Re: waiting for more than one cond in pThread question
- From: Keith Willis <keith at bytebrothers dot co dot uk>
- To: pthreads-win32 at sourceware dot cygnus dot com
- Cc: nir dot nizry at bluesoft-inc dot com
- Date: Tue, 02 Apr 2002 15:46:27 +0100
- Subject: Re: waiting for more than one cond in pThread question
- Organization: Bytebrothers Software (UK)
- References: <JEEHINPAHDLKGLNOLIOCAEDICAAA.nir.nizry@bluesoft-inc.com>
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