Date: Thu, 15 Oct 1998 09:25:05 -0700 (PDT) From: info@highwind.com To: freebsd-gnats-submit@FreeBSD.ORG Subject: kern/8335: pthread_cond_timedwait() is broken Message-ID: <199810151625.JAA15891@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 8335 >Category: kern >Synopsis: pthread_cond_timedwait() is broken >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Oct 15 09:30:00 PDT 1998 >Last-Modified: >Originator: Robert Fleischman >Organization: HighWind Software >Release: 3.0 >Environment: FreeBSD zonda.highwind.com 3.0-19980831-SNAP FreeBSD 3.0-19980831-SNAP #0: Mon Aug 31 14:03:19 GMT 1998 root@make.ican.net:/usr/src/sys/compile/GENERIC i386 >Description: It appears that in recent 3.0 kernels, pthread_cond_timedwait() doesn't work properly. This is true even with the latest libc_r. I've included a test program. >How-To-Repeat: /* Illustration of FreeBSD pthread_cond_timedwait() bug This program sets up a timed conditional wait. It just calls cond_timed_wait(). This should BLOCK for 15 seconds and the program should terminate normally. However, because of some bugs in FreeBSD, the cond_timed_wait returns with no error. It looks as if someone has signaled the condition. Clearly, that is impossible and there is some kind of bug! g++ -o condBug -D_REENTRANT -D_THREAD_SAFE -g -Wall condBug.C -pthread */ #include <assert.h> #include <pthread.h> #include <stdlib.h> int main(int, char **) { pthread_mutex_t lock; pthread_cond_t condition; // Initialize Lock pthread_mutexattr_t lock_attr; assert(!::pthread_mutexattr_init(&lock_attr)); assert(!::pthread_mutex_init(&lock, &lock_attr)); assert(!::pthread_mutexattr_destroy(&lock_attr)); // Initialize Condition pthread_condattr_t cond_attr; assert(!::pthread_condattr_init(&cond_attr)); assert(!::pthread_cond_init(&condition, &cond_attr)); assert(!::pthread_condattr_destroy(&cond_attr)); // Grab current time time_t currentTime = ::time(0); // Lock the lock assert(!::pthread_mutex_lock(&lock)); // Wait in the condition for 15 seconds timespec timeOut; timeOut.tv_sec = currentTime + 15; timeOut.tv_nsec = 0; int err = ::pthread_cond_timedwait(&condition, &lock, &timeOut); // We better get an error (we should have TIMED OUT!) assert(err); // 15 seconds SHOULD have passed, so 5 seconds DEFINATELY should have!! assert(::time(0) >= currentTime + 5); return EXIT_SUCCESS; } >Fix: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199810151625.JAA15891>