Subj : Re: Predicate for pthread_cond_timedwait() ?? To : comp.programming.threads From : recvfrom@gmail.com Date : Thu Mar 17 2005 01:59 pm David Schwartz wrote: > 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); Thanks so much for your response!!! All good pointers. I may try nanosleep too -- a bit more code to cover the interrupt case, but the intent is more obvious. Thanks again! -r .