NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
lib/44756: pthread_cond_timedwait() sometimes returns error code 3 (ESRCH)
>Number: 44756
>Category: lib
>Synopsis: pthread_cond_timedwait() sometimes returns error code 3 (ESRCH)
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Mar 22 21:00:01 +0000 2011
>Originator: Sad Clouds
>Release: 5.1
>Organization:
>Environment:
NetBSD atom 5.1_STABLE NetBSD 5.1_STABLE (GENERIC) #6: Tue Mar 15 12:39:43 GMT
2011 roman@atom:/opt/obj.amd64/sys/arch/amd64/compile/GENERIC amd64
>Description:
pthread_cond_timedwait() sometimes returns error code 3 (ESRCH), this should
never occur. The problem is likely to be seen when creating and exiting threads
in a loop, when those threads call pthread_cond_timedwait().
>How-To-Repeat:
The following test program demonstrates the problem. It may take a while for
the error to occur, but sooner or later it repeatedly occurs, e.g.:
atom$ gcc -O tmp.c -lpthread
atom$ ./a.out
pthread_cond_timedwait returned = 3
#include <stdlib.h>
#include <errno.h>
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
void *thread_func(void *arg)
{
struct timespec ts;
int int_ret;
int i = 0;
while (1)
{
if (i++ >= 10000)
pthread_exit(NULL);
if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
abort();
/*
Set to 1 second in the past, this should make
pthread_cond_timedwait()
return immediately with ETIMEDOUT.
*/
ts.tv_sec -= 1;
if (pthread_mutex_lock(&mutex) != 0)
abort();
int_ret = pthread_cond_timedwait(&cond, &mutex, &ts);
if (int_ret != 0 && int_ret != ETIMEDOUT)
{
/*
Sometimes pthread_cond_timedwait() returns 3.
This should never happen.
*/
printf("pthread_cond_timedwait returned = %d\n",
int_ret);
exit(1);
}
if (pthread_mutex_unlock(&mutex) != 0)
abort();
}
}
int main(void)
{
pthread_t tid[64];
int i;
while (1)
{
for (i = 0; i < 64; i++)
{
if (pthread_create(&tid[i], NULL, thread_func, NULL) !=
0)
{
abort();
}
}
for (i = 0; i < 64; i++)
{
if (pthread_join(tid[i], NULL) != 0)
abort();
}
}
pthread_exit(NULL);
}
>Fix:
Home |
Main Index |
Thread Index |
Old Index