Subj : Re: How to wait on multiple condition variables or implement a similar semantics To : comp.programming.threads From : Joe Seigh Date : Tue Mar 15 2005 10:30 pm On 15 Mar 2005 18:32:02 -0800, vikky@gmail.com wrote: > Hi , > I am porting an application from windows to linux. It uses function > WaitForMultipleObjects() to wait on multiple events and on the basis of > what event is signalled (which is specified by the functions return > value) it takes furthur action. The function is actually being used > here to wait for only two events,in mode where it returns if any of the > event is signalled. The first one being any event while the second one > always being the event signalled when the application is closing. > I am using pthreads in linux to port the application but i got stuck on > how to implement WaitForMultipleObjects() semantics. The closest > analogue i found to WaitForSingleObject() is using condition variables > and waiting on them. But alas i can't find any function in pthread > library that can wait on multiple condition varibles. I want to ask how > a suitable replacement for WaitForMultipleObjects() can be made. > You have to use the same condition variable. For bWaitAll == true while (!(cond1 && cond2 && ...)) pthread_cond_wait(&cvar, &mutex); > For bWaitAll == false while (!(cond1 || cond2 || ...)) pthread_cond_wait(&cvar, &mutex); Use broadcast instead of signal if you have multiple waiters. There are emulations of the windows WaitForMultipleObjects out there, but they're pretty inefficient. So is the windows implementation but that's hidden from you. -- Joe Seigh .