GNU bug report logs - #55356
join-thread unusable if timeout was hit

Previous Next

Package: guile;

Reported by: angry rectangle <angryrectangle <at> cock.li>

Date: Wed, 11 May 2022 02:30:01 UTC

Severity: normal

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Olivier Dion <olivier.dion <at> polymtl.ca>
To: 55356 <at> debbugs.gnu.org
Cc: Olivier Dion <olivier-dion <at> proton.me>
Subject: bug#55356: [PATCH] Always release thread data mutex in join-thread.
Date: Sun, 16 Oct 2022 11:36:02 -0400
From: Olivier Dion <olivier-dion <at> 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





This bug report was last modified 1 year and 118 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.