From owner-freebsd-threads@FreeBSD.ORG Tue Jan 31 22:18:33 2006 Return-Path: X-Original-To: freebsd-threads@freebsd.org Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D51CC16A420 for ; Tue, 31 Jan 2006 22:18:33 +0000 (GMT) (envelope-from lists@intricatesoftware.com) Received: from mta5.srv.hcvlny.cv.net (mta5.srv.hcvlny.cv.net [167.206.4.200]) by mx1.FreeBSD.org (Postfix) with ESMTP id 89AFA43D7F for ; Tue, 31 Jan 2006 22:18:33 +0000 (GMT) (envelope-from lists@intricatesoftware.com) Received: from [172.16.1.72] (ool-457a77e8.dyn.optonline.net [69.122.119.232]) by mta5.srv.hcvlny.cv.net (Sun Java System Messaging Server 6.2-4.03 (built Sep 22 2005)) with ESMTP id <0ITZ00JGG9YC1C10@mta5.srv.hcvlny.cv.net> for freebsd-threads@freebsd.org; Tue, 31 Jan 2006 17:18:13 -0500 (EST) Date: Tue, 31 Jan 2006 17:18:11 -0500 From: Kurt Miller To: freebsd-threads@freebsd.org Message-id: <200601311718.11683.lists@intricatesoftware.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT Content-disposition: inline User-Agent: KMail/1.9 Subject: kse: high prio threads starving low prio threads X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: kurt@intricatesoftware.com List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Jan 2006 22:18:33 -0000 I'm working on 1.5 jdk certification on 5.4 and 6.0. One of the jck tests hangs because a high priority thread that is yielding is starving the lower priority threads. The following program demonstrates this problem. Using libthr the program finishes. Using kse hangs using all three scheduling policies. Is this the expected behavior of kse? Is there a work-around to the starving issue? Thanks, -Kurt #include #include #include #include #include #include #include #include volatile int init=0; volatile int interrupt=0; static void * yielder(void *arg) { init = 1; while (1) { pthread_yield(); } } static void sighandler(int sig) { interrupt = 1; printf("sighandler\n"); } static void waitForInit() { struct timespec t, rt; while (init == 0) { t.tv_sec = 0; t.tv_nsec = 100000; nanosleep(&t, &rt); } } static void waitForInterrupt() { struct timespec t, rt; while (interrupt == 0) { t.tv_sec = 0; t.tv_nsec = 100000; nanosleep(&t, &rt); } } int main(int argc, char *argv[]) { pthread_t yldr; pthread_attr_t attr; struct sigaction act; /* Install a signal handler for SIGUSR1 */ sigemptyset (&act.sa_mask); sigaddset (&act.sa_mask, SIGUSR1); act.sa_handler = sighandler; act.sa_flags = 0; sigaction (SIGUSR1, &act, NULL); pthread_attr_init(&attr); pthread_attr_setschedpolicy(&attr, SCHED_FIFO); pthread_create(&yldr, &attr, yielder, NULL); pthread_setprio(yldr, 16); waitForInit(); if(pthread_kill(yldr, SIGUSR1) != 0) printf("pthread_kill failed with errno = %d\n", errno); waitForInterrupt(); }