GNU bug report logs -
#61058
[PATCH] Fix asymetric mutex locking when joining thread.
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 61058 in the body.
You can then email your comments to 61058 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-guile <at> gnu.org
:
bug#61058
; Package
guile
.
(Wed, 25 Jan 2023 15:25:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Olivier Dion <olivier.dion <at> polymtl.ca>
:
New bug report received and forwarded. Copy sent to
bug-guile <at> gnu.org
.
(Wed, 25 Jan 2023 15:25:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
From: Olivier Dion <olivier-dion <at> 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
Information forwarded
to
bug-guile <at> gnu.org
:
bug#61058
; Package
guile
.
(Thu, 25 Jan 2024 21:47:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 61058 <at> debbugs.gnu.org (full text, mbox):
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.
* test-suite/tests/threads.test (join-thread): New test to ensure the
mutex is released
---
module/ice-9/threads.scm | 4 +++-
test-suite/tests/threads.test | 13 ++++++++++++-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/module/ice-9/threads.scm b/module/ice-9/threads.scm
index 048d8b085..a1e43b9fa 100644
--- a/module/ice-9/threads.scm
+++ b/module/ice-9/threads.scm
@@ -204,7 +204,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
diff --git a/test-suite/tests/threads.test b/test-suite/tests/threads.test
index efdf36db2..af8c8c75b 100644
--- a/test-suite/tests/threads.test
+++ b/test-suite/tests/threads.test
@@ -332,7 +332,18 @@
(sleep 2)
(system-async-mark aproc)
(join-thread other-thread)))
- #t))
+ #t)
+
+ (pass-if "do not throw exception if trying to join after timeout"
+ (let ((other-thread (begin-thread (pause))))
+ (dynamic-wind
+ (const #f)
+ (lambda ()
+ (join-thread other-thread 1)
+ (join-thread other-thread 1)
+ #t)
+ (lambda ()
+ (cancel-thread other-thread))))))
;;
;; thread cancellation
--
2.41.0
Reply sent
to
Ludovic Courtès <ludo <at> gnu.org>
:
You have taken responsibility.
(Thu, 25 Jan 2024 22:15:03 GMT)
Full text and
rfc822 format available.
Notification sent
to
Olivier Dion <olivier.dion <at> polymtl.ca>
:
bug acknowledged by developer.
(Thu, 25 Jan 2024 22:15:03 GMT)
Full text and
rfc822 format available.
Message #13 received at 61058-done <at> debbugs.gnu.org (full text, mbox):
Hello,
Olivier Dion <olivier.dion <at> polymtl.ca> skribis:
> 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.
> * test-suite/tests/threads.test (join-thread): New test to ensure the
> mutex is released
Pushed as 455ee49f5573baa1bc5237a8d49083ce588a13ee with a ‘NEWS’ entry
and an additional comment in the test.
Thanks!
Ludo’.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Fri, 23 Feb 2024 12:24:12 GMT)
Full text and
rfc822 format available.
This bug report was last modified 62 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.