* bug#55356: join-thread unusable if timeout was hit
@ 2022-05-11 0:42 angry rectangle
2022-10-16 15:36 ` bug#55356: [PATCH] Always release thread data mutex in join-thread Olivier Dion via Bug reports for GUILE, GNU's Ubiquitous Extension Language
0 siblings, 1 reply; 2+ messages in thread
From: angry rectangle @ 2022-05-11 0:42 UTC (permalink / raw)
To: 55356
If join-thread is called after a previous call to join-thread hits the timeout, a "mutex already locked by thread" error is thrown.
Working example:
(use-modules (ice-9 threads))
(define t (call-with-new-thread
(lambda _
(let r ()
(sleep 1)
(r)))))
(join-thread t (current-time))
(join-thread t (current-time)) ;; exception here
my guile version: latest git. cc455976813ab94de121395982435430874cbf58
my OS: guix on amd64
^ permalink raw reply [flat|nested] 2+ messages in thread
* bug#55356: [PATCH] Always release thread data mutex in join-thread.
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
0 siblings, 0 replies; 2+ messages in thread
From: Olivier Dion via Bug reports for GUILE, GNU's Ubiquitous Extension Language @ 2022-10-16 15:36 UTC (permalink / raw)
To: 55356; +Cc: Olivier Dion
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-16 15:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-11 0:42 bug#55356: join-thread unusable if timeout was hit angry rectangle
2022-10-16 15:36 ` bug#55356: [PATCH] Always release thread data mutex in join-thread Olivier Dion via Bug reports for GUILE, GNU's Ubiquitous Extension Language
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).