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: 55356@debbugs.gnu.org
Cc: Olivier Dion <olivier-dion@proton.me>
Subject: bug#55356: [PATCH] Always release thread data mutex in join-thread.
Date: Sun, 16 Oct 2022 11:36:02 -0400	[thread overview]
Message-ID: <20221016153602.3580-1-olivier.dion@polymtl.ca> (raw)
In-Reply-To: <87fslgg65p.fsf@cock.li>

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

Currently the mutex is only unlocked when results are available.
However, it is not unlocked when we get a timeout from the condition
variable.

* module/ice-9/threads.scm (join-thread): Use with-mutex to ensure that
the thread data mutex is always unlocked.
---
 module/ice-9/threads.scm | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/module/ice-9/threads.scm b/module/ice-9/threads.scm
index c42bd266f..8993596e4 100644
--- a/module/ice-9/threads.scm
+++ b/module/ice-9/threads.scm
@@ -186,18 +186,17 @@ terminates, unless the target @var{thread} has already terminated."
   (match (thread-join-data thread)
     (#f (error "foreign thread cannot be joined" thread))
     ((cv . mutex)
-     (lock-mutex mutex)
-     (let lp ()
-       (cond
-        ((%thread-results cv)
-         => (lambda (results)
-              (unlock-mutex mutex)
-              (apply values results)))
-        ((if timeout
-             (wait-condition-variable cv mutex timeout)
-             (wait-condition-variable cv mutex))
-         (lp))
-        (else timeoutval))))))
+     (with-mutex mutex
+       (let lp ()
+         (cond
+          ((%thread-results cv)
+           => (lambda (results)
+                (apply values results)))
+          ((if timeout
+               (wait-condition-variable cv mutex timeout)
+               (wait-condition-variable cv mutex))
+           (lp))
+          (else timeoutval)))))))
 
 (define* (try-mutex mutex)
   "Try to lock @var{mutex}.  If the mutex is already locked, return
-- 
2.37.3






      reply	other threads:[~2022-10-16 15:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-11  0:42 bug#55356: join-thread unusable if timeout was hit angry rectangle
2022-10-16 15:36 ` Olivier Dion via Bug reports for GUILE, GNU's Ubiquitous Extension Language [this message]

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=20221016153602.3580-1-olivier.dion@polymtl.ca \
    --to=bug-guile@gnu.org \
    --cc=55356@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).