Subj : Re: pthread_timed_wait To : comp.programming.threads From : loic-dev Date : Wed Jun 01 2005 09:43 am Hi Mike, > I'm using the LinuxThreads implementation of pthreads and I'm having > trouble working out the precise meaning of the documentation. Ok, let's see... > The /pthread_cond_timedwait/() function shall be equivalent to > /pthread_cond_wait/(), except that an error is returned if the absolute > time specified by /abstime/ passes (that is, system time equals or > exceeds /abstime/) before the condition /cond/ is signaled or > broadcasted, or if the absolute time specified by /abstime/ has already > been passed at the time of the call. > ... Here in this text, SUSv3 only mention that "AN ERROR" shall be returned, but it doesn't tell yet which one! The important text comes in the section "ERRORS" The pthread_cond_timedwait() function shall fail if: [ETIMEDOUT] The time specified by abstime to pthread_cond_timedwait() has passed. [EINVAL] This is a "shall" clause. That means: in the case when abstime has passed, the error ETIMEDOUT - and exactly that error - has to be reported. > I assume this means if ptherad_cond_timedwait is called with an absolute > time before the current time then the error code ETIMEOUT is returned? > (same as normal timeout) Unless I misread the standard, that's what's SUSv3 says. (this is the behavior one would expect BTW). > However, I don't know if it's my implementation but if I call timed wait > with a time in the past the function returns EINVAL. If this is the case, then it doesn't conform to SUSv3. But my guess is rather than the value specified by abstime is invalid. That's basically the case when: 1) pointer to timespec is NULL. 2) tv_nsec<0 || tv_nsec>=1e9. > From the documentation EINVAL is returned if the abstime passed is invalid. That's correct. See above for the definition of "invalid". > Is a abstime less than the system time an invalid time? No, it shouldn't be. Regards, Loic. .