pthread_cond_timedwait() bug in Tiger?
pthread_cond_timedwait() bug in Tiger?
- Subject: pthread_cond_timedwait() bug in Tiger?
- From: Guenter Obiltschnig <email@hidden>
- Date: Fri, 13 May 2005 19:21:03 +0200
Hello,
I have a strange problem with pthread_cond_timedwait() on 10.4.
The following code snipped works fine on 10.3 (and a bunch of other
POSIX platforms).
On 10.4 however, if milliseconds == 0, the program hangs forever in
pthread_cond_timedwait() instead
of returning ETIMEDOUT.
milliseconds == 0 basically means that the absolute time value passed
to pthread_cond_timedwait()
is the result of gettimeofday(). If milliseconds has a value of 10,
which means that the absolute
time passed to pthread_cond_timedwait() is about 10ms into the
future, pthread_cond_timedwait()
returns ETIMEDOUT as expected. Could it be that there is a bug in
pthread_cond_timedwait() that
causes it to block forever if the absolute time value passed to it
lies in the past?
struct timeval tv;
gettimeofday(&tv, NULL);
struct timespec abstime;
abstime.tv_sec = tv.tv_sec + milliseconds / 1000;
abstime.tv_nsec = tv.tv_usec*1000 + (milliseconds % 1000)*1000000;
if (abstime.tv_nsec >= 1000000000)
{
abstime.tv_nsec -= 1000000000;
abstime.tv_sec++;
}
pthread_mutex_lock(&_mutex); // error handling omitted
while (...)
{
int rc = pthread_cond_timedwait(&_cond, &_mutex, &abstime)))
if (rc == ETIMEDOUT) // we never get here if milliseconds == 0
...
}
Any ideas?
Thanks and best regards,
Günter Obiltschnig
http://www.obiltschnig.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden