1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-17 01:00:20 +02:00

Remove possible deadlock in scm_join_thread

* libguile/threads.c (scm_join_thread): Always recheck t->exited
  before calling block_self again, in case thread t has now exited.

* test-suite/tests/threads.test (joining): New test.
This commit is contained in:
Neil Jerram 2009-05-20 21:55:35 +01:00
parent 3ed47d2203
commit 66f3b6c1b0
2 changed files with 40 additions and 11 deletions

View file

@ -934,17 +934,14 @@ SCM_DEFINE (scm_join_thread, "join-thread", 1, 0, 0,
scm_i_scm_pthread_mutex_lock (&thread_admin_mutex);
t = SCM_I_THREAD_DATA (thread);
if (!t->exited)
while (!t->exited)
{
while (1)
{
block_self (t->join_queue, thread, &thread_admin_mutex, NULL);
if (t->exited)
break;
scm_i_pthread_mutex_unlock (&thread_admin_mutex);
SCM_TICK;
scm_i_scm_pthread_mutex_lock (&thread_admin_mutex);
}
block_self (t->join_queue, thread, &thread_admin_mutex, NULL);
if (t->exited)
break;
scm_i_pthread_mutex_unlock (&thread_admin_mutex);
SCM_TICK;
scm_i_scm_pthread_mutex_lock (&thread_admin_mutex);
}
res = t->result;