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


Keith Willis wrote:
> 
> 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();
> ============================================================
> 

... except you need to unlock the mutex after you've finished
using or copying the predicate values locally, otherwise
you've got a race condition.

Ross


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