pthread_cond_signal w/suspended threads
Kurt Miller
lists at intricatesoftware.com
Wed May 24 22:14:31 UTC 2006
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);
}
More information about the freebsd-threads
mailing list