Subj : Re: Predicate for pthread_cond_timedwait() ?? To : comp.programming.threads From : David Schwartz Date : Wed Mar 16 2005 06:02 pm wrote in message news:1111022385.023902.120750@l41g2000cwc.googlegroups.com... > Rather than mess with timers and signals in a threaded app, > I tried using pthread_cond_timedwait() for a condvar that > will never be signaled. Is this a good approach? It seems > to work fine. It's adequate, but usleep/nanosleep would be cleaner. > Also, I assume this call should be wrapped > in a loop, since there is no guarantee that the call could > return for some 'other' reason (whatever that might be, I'm > not sure). Right. > What should be the predicate for this loop? A > zero return value? E.g.: > > r = 0; > while (r == 0) > { > r = pthread_cond_timedwait (&x->condvar, &x->mutex, &ts); > } More like: int ret; pthread_mutex_lock(&x->mutex); do ret=pthread_cond_timedwait(&x->condvar, &x->mutex, &ts); while(ret!=ETIMEDOUT); pthread_mutex_unlock(&x->mutex); DS .