Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 Jan 2006 17:18:11 -0500
From:      Kurt Miller <lists@intricatesoftware.com>
To:        freebsd-threads@freebsd.org
Subject:   kse: high prio threads starving low prio threads
Message-ID:  <200601311718.11683.lists@intricatesoftware.com>

next in thread | raw e-mail | index | archive | help
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 <pthread.h>
#include <unistd.h>
#include <signal.h>
#include <inttypes.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

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();
}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200601311718.11683.lists>