unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Olivier Dion via "Bug reports for GUILE, GNU's Ubiquitous Extension Language" <bug-guile@gnu.org>
To: 61058@debbugs.gnu.org
Cc: Olivier Dion <olivier-dion@proton.me>
Subject: bug#61058: [PATCH] Fix asymetric mutex locking when joining thread.
Date: Wed, 25 Jan 2023 10:24:03 -0500	[thread overview]
Message-ID: <20230125152403.19091-1-olivier.dion@polymtl.ca> (raw)

From: Olivier Dion <olivier-dion@proton.me>

If `join-thread' timeout, the thread mutex is not unlocked,
resulting in deadlock to the next call to it or deadlock of the
thread itself when it terminates.

Thus, always unlock the mutex.

Fix: #55356

* module/ice-9/threads.scm (join-thread): Always unlock thread mutex.
---
 module/ice-9/threads.scm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/module/ice-9/threads.scm b/module/ice-9/threads.scm
index c42bd266f..962caee70 100644
--- a/module/ice-9/threads.scm
+++ b/module/ice-9/threads.scm
@@ -197,7 +197,9 @@ terminates, unless the target @var{thread} has already terminated."
              (wait-condition-variable cv mutex timeout)
              (wait-condition-variable cv mutex))
          (lp))
-        (else timeoutval))))))
+        (else
+         (unlock-mutex mutex)
+         timeoutval))))))
 
 (define* (try-mutex mutex)
   "Try to lock @var{mutex}.  If the mutex is already locked, return
-- 
2.39.1






             reply	other threads:[~2023-01-25 15:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-25 15:24 Olivier Dion via Bug reports for GUILE, GNU's Ubiquitous Extension Language [this message]
2024-01-25 21:45 ` bug#61058: [PATCH v2] Fix asymetric mutex locking when joining thread Olivier Dion
2024-01-25 22:14   ` Ludovic Courtès

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=20230125152403.19091-1-olivier.dion@polymtl.ca \
    --to=bug-guile@gnu.org \
    --cc=61058@debbugs.gnu.org \
    --cc=olivier-dion@proton.me \
    --cc=olivier.dion@polymtl.ca \
    /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).