unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: "Julian Graham" <joolean@gmail.com>
To: "Neil Jerram" <neiljerram@googlemail.com>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: deadlock in scm_join_thread(_timed)
Date: Mon, 26 May 2008 22:53:20 -0400	[thread overview]
Message-ID: <2bc5f8210805261953s18bef0b9i9e32ee7cb4486c0e@mail.gmail.com> (raw)
In-Reply-To: <49dd78620805250616n47ae2ecfjfe4015f066199d24@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 709 bytes --]

Hi Neil,

> Based on the synopsis above, I agree that moving step 1 inside the loop
> should fix this.  In addition, though, I think it would be very good if we
> could add a minimal test that currently reproduces the deadlock, and so will
> serve to guard against future regressions here.  Do you have such a test?

I don't -- it seems to be pretty dependent on timing.  I noticed it
while running my SRFI-18 test suite in a loop, and it took hours to
trigger.  Any suggestions?


> No need for a patch against both 1.8 and 1.9; just one will do, and git
> cherry-pick will handle the other for us (unless the fix is significantly
> different in the two branches).

Okay, find it attached.


Regards,
Julian

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-threads.c-join_thread_timed-Avoid-deadlock-by-a.patch --]
[-- Type: text/x-diff; name=0001-threads.c-join_thread_timed-Avoid-deadlock-by-a.patch, Size: 1467 bytes --]

From 1a90835bd4c646fb1776d6a83489820772fb5bbd Mon Sep 17 00:00:00 2001
From: Julian Graham <julian@smokebottle.(none)>
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


  reply	other threads:[~2008-05-27  2:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-25  5:33 deadlock in scm_join_thread(_timed) Julian Graham
2008-05-25 13:16 ` Neil Jerram
2008-05-27  2:53   ` Julian Graham [this message]
2009-05-20 18:24     ` Neil Jerram
2009-05-20 20:58       ` Neil Jerram
2009-05-20 22:25         ` Ludovic Courtès
2009-05-23 22:57           ` Neil Jerram
2009-05-24 14:03             ` Ludovic Courtès
2009-05-24 21:26               ` Neil Jerram

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2bc5f8210805261953s18bef0b9i9e32ee7cb4486c0e@mail.gmail.com \
    --to=joolean@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=neiljerram@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).