From owner-freebsd-current Thu Oct 29 01:42:38 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id BAA28906 for freebsd-current-outgoing; Thu, 29 Oct 1998 01:42:38 -0800 (PST) (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 BAA28901 for ; Thu, 29 Oct 1998 01:42:36 -0800 (PST) (envelope-from info@highwind.com) Received: (from info@localhost) by highwind.com (8.8.6/8.8.6) id EAA21626; Thu, 29 Oct 1998 04:42:34 -0500 (EST) Date: Thu, 29 Oct 1998 04:42:34 -0500 (EST) Message-Id: <199810290942.EAA21626@highwind.com> From: HighWind Software Information To: current@FreeBSD.ORG Subject: Thread Scheduler bug Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I'm worried about the thread scheduler. Here is a disturbing test program out for folks to try. As you can probably guess, we are now battling the scheduler because some of our application's threads are getting seriously starved by other threads. I'm compiling on 3.0 with the latest libc_r. This program works fine on IRIX, Solaris, and (gasp..) Linux. Isn't FreeBSD supposed to handle this without the explicit yield() call? -Rob ---- /***************************************************************************** File: schedBug.C Contents: FreeBSD Scheduling Bug Illustrator This program SHOULD print "Marking Time : 1", etc. However, the thread scheduler appears to NOT schedule the markTimeThread because the ioThread is so busy. If you uncomment the "::pthread_yield()" it works a little better. Ideally, you should get a print every second. g++ -o schedBug -D_REENTRANT -D_THREAD_SAFE -g -Wall schedBug.C -pthread *****************************************************************************/ #include #include #include #include #include #include #include unsigned int LENGTH = 1024 * 1024; void *ioThread(void *) { char *data = new char[LENGTH]; ::memset(data, 0, LENGTH); while (true) { int file = ::open("scrap", O_CREAT | O_TRUNC | O_WRONLY, 0666); assert(file != -1); assert(::write(file, data, LENGTH) == static_cast(LENGTH)); // // Uncomment the next line to make things a bit better // // ::pthread_yield(); // assert(!::close(file)); } } void *markTimeThread(void *) { time_t start = ::time(0); while (true) { timeval timeout; timeout.tv_sec = 1; timeout.tv_usec = 0; ::select(0, 0, 0, 0, &timeout); ::printf("Marking Time: %lu\n", ::time(0) - start); } } int main(int, char **) { // Set up Thread Arguments pthread_t tid; pthread_attr_t attr; assert(!::pthread_attr_init(&attr)); assert(!::pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED)); // Spawn markTimeThread assert(!::pthread_create(&tid, &attr, markTimeThread, 0)); // Spawn ioThread assert(!::pthread_create(&tid, &attr, ioThread, 0)); // main() goes away for a long time timeval timeout; timeout.tv_sec = 3600; 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