From 1a90835bd4c646fb1776d6a83489820772fb5bbd Mon Sep 17 00:00:00 2001 From: Julian Graham Date: Mon, 26 May 2008 21:27:24 -0400 Subject: [PATCH] * threads.c (join_thread_timed): Avoid deadlock by always checking thread exit status. --- libguile/threads.c | 32 ++++++++++++-------------------- 1 files changed, 12 insertions(+), 20 deletions(-) diff --git a/libguile/threads.c b/libguile/threads.c index bf4ab16..e875cdf 100644 --- a/libguile/threads.c +++ b/libguile/threads.c @@ -1094,29 +1094,21 @@ SCM_DEFINE (scm_join_thread_timed, "join-thread", 1, 2, 0, timeout_ptr = &ctimeout; } - if (t->exited) - res = t->result; - else + while (1) { - while (1) + int err = 0; + if (t->exited) { - int err = block_self (t->join_queue, thread, &t->admin_mutex, - timeout_ptr); - if (err == 0) - { - if (t->exited) - { - res = t->result; - break; - } - } - else if (err == ETIMEDOUT) - break; - - scm_i_pthread_mutex_unlock (&t->admin_mutex); - SCM_TICK; - scm_i_scm_pthread_mutex_lock (&t->admin_mutex); + res = t->result; + break; } + err = block_self (t->join_queue, thread, &t->admin_mutex, timeout_ptr); + if (err == ETIMEDOUT) + break; + + scm_i_pthread_mutex_unlock (&t->admin_mutex); + SCM_TICK; + scm_i_scm_pthread_mutex_lock (&t->admin_mutex); } scm_i_pthread_mutex_unlock (&t->admin_mutex); -- 1.5.4.3