Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 24 May 2006 18:14:11 -0400
From:      Kurt Miller <lists@intricatesoftware.com>
To:        freebsd-threads@freebsd.org
Subject:   pthread_cond_signal w/suspended threads
Message-ID:  <200605241814.11452.lists@intricatesoftware.com>

next in thread | raw e-mail | index | archive | help
I've been working on an intermittent deadlock in
the jvm and have isolated it to the following issue.
When multiple threads are waiting on a condition
variable and some of those threads have been suspended
with pthread_suspend_np(), there is an expectation that
pthread_cond_signal() will signal an unsuspended thread
first. However, the following program shows this is not
the case on 6.1-release/kse (thr works as expected).

Can kse behavior be changed to signal unsuspended
threads first?

#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <pthread_np.h>

pthread_cond_t  cond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

static void *
start_routine(void *arg)
{
    pthread_mutex_lock(&mutex);
    pthread_cond_wait(&cond, &mutex);
    printf("unblocked %d\n", (int)arg);
    pthread_mutex_unlock(&mutex);
    return (0);
}

int
main(int argc, char *argv[])
{
    pthread_t thread1;
    pthread_t thread2;

    pthread_create(&thread1, NULL, start_routine, (void *)1);
    sleep(1);
    pthread_create(&thread2, NULL, start_routine, (void *)2);
    sleep(1);
    pthread_suspend_np(thread1);
    pthread_cond_signal(&cond);
    sleep(1);
    pthread_resume_np(thread1);
    sleep(1);
    return (0);
}



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