From owner-freebsd-current Mon Oct 19 11:36:26 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id LAA04609 for freebsd-current-outgoing; Mon, 19 Oct 1998 11:36:26 -0700 (PDT) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from highwind.com (hurricane.highwind.com [209.61.45.50]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id LAA04604 for ; Mon, 19 Oct 1998 11:36:24 -0700 (PDT) (envelope-from info@highwind.com) Received: (from info@localhost) by highwind.com (8.8.6/8.8.6) id OAA20137; Mon, 19 Oct 1998 14:35:40 -0400 (EDT) Date: Mon, 19 Oct 1998 14:35:40 -0400 (EDT) Message-Id: <199810191835.OAA20137@highwind.com> From: HighWind Software Information To: current@FreeBSD.ORG Subject: Another Serious libc_r problem Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG We found another libc_r problem which is spinning the CPU at 100%. This makes it impossible for our application to work at all. FreeBSD 3.0 kernel from August. The LATEST libc_r. Tested this on another FreeBSD with a much more recent kernel. Same result. The CPU spins and the threads don't get the condition. Program works fine on other operating systems. After the 3 second start up, it prints nice stream of "Signalling" and "Got Condition!". On FreeBSD 3.0, it prints "Signalling" twice and then spins the CPU. Help is always appreciated. -Rob --- /* Illustration of FreeBSD pthread_cond_wait() bug This program sets up a conditional wait and fires off a dozen threads that simply wait for the condition. Once the threads are started, the main thread loops signalling the condition once a second. Normally, this should result in "Signalling" and "Got Condition" being printed once a second. However, because of some bugs in FreeBSD, the pthread_cond_wait() spins the CPU and no progress is made. g++ -o condWaitBug -D_REENTRANT -D_THREAD_SAFE -g -Wall condWaitBug.C -pthread */ #include #include #include #include #include pthread_mutex_t lock; pthread_cond_t condition; static void *condThread(void *) { // Wait until we are signalled, then print. while (true) { assert(!::pthread_cond_wait(&condition, &lock)); ::printf("Got Condition!\n"); } } int main(int, char **) { // 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)); // Lock the lock assert(!::pthread_mutex_lock(&lock)); // Spawn off a dozen threads to get signalled for (int j = 0; j < 12; ++j) { pthread_t tid; pthread_attr_t attr; assert(!::pthread_attr_init(&attr)); assert(!::pthread_create(&tid, &attr, condThread, 0)); assert(!::pthread_attr_destroy(&attr)); } // Sleep for 3 seconds to make sure the threads started up. timeval timeout; timeout.tv_sec = 3; timeout.tv_usec = 0; ::select(0, 0, 0, 0, &timeout); for (int k = 0; k < 60; ++k) { ::printf("Signalling\n"); ::pthread_cond_signal(&condition); // Sleep for a second timeout.tv_sec = 1; timeout.tv_usec = 0; ::select(0, 0, 0, 0, &timeout); } return EXIT_SUCCESS; } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message