From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Olivier Dion via "Bug reports for GUILE, GNU's Ubiquitous Extension Language" Newsgroups: gmane.lisp.guile.bugs Subject: bug#55356: [PATCH] Always release thread data mutex in join-thread. Date: Sun, 16 Oct 2022 11:36:02 -0400 Message-ID: <20221016153602.3580-1-olivier.dion@polymtl.ca> References: <87fslgg65p.fsf@cock.li> Reply-To: Olivier Dion Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27894"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Olivier Dion To: 55356@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Sun Oct 16 17:37:09 2022 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ok5hM-00072F-Q0 for guile-bugs@m.gmane-mx.org; Sun, 16 Oct 2022 17:37:09 +0200 Original-Received: from localhost ([::1]:39798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ok5hL-0003ep-SU for guile-bugs@m.gmane-mx.org; Sun, 16 Oct 2022 11:37:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36702) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ok5hG-0003eP-KR for bug-guile@gnu.org; Sun, 16 Oct 2022 11:37:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:46832) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ok5hG-0003Ws-Ci for bug-guile@gnu.org; Sun, 16 Oct 2022 11:37:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ok5hG-0005gZ-3w for bug-guile@gnu.org; Sun, 16 Oct 2022 11:37:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <87fslgg65p.fsf@cock.li> Resent-From: Olivier Dion Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sun, 16 Oct 2022 15:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55356 X-GNU-PR-Package: guile Original-Received: via spool by 55356-submit@debbugs.gnu.org id=B55356.166593458721807 (code B ref 55356); Sun, 16 Oct 2022 15:37:02 +0000 Original-Received: (at 55356) by debbugs.gnu.org; 16 Oct 2022 15:36:27 +0000 Original-Received: from localhost ([127.0.0.1]:45910 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ok5gh-0005fd-BQ for submit@debbugs.gnu.org; Sun, 16 Oct 2022 11:36:27 -0400 Original-Received: from smtp.polymtl.ca ([132.207.4.11]:35336) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ok5ge-0005fM-Ja for 55356@debbugs.gnu.org; Sun, 16 Oct 2022 11:36:25 -0400 Original-Received: from laura.hitronhub.home (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 29GFa5sg032159 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Sun, 16 Oct 2022 11:36:16 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 29GFa5sg032159 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1665934577; bh=snaCXDRniNbZlsXuFaBE9DnbZWOdHZcsacdDS0RefWo=; h=From:To:Cc:Subject:Date:From; b=hcb5+U4BZUOn3N7H7rlsldNZ7PcQJOYPohlZ+NMcRUOIbKwRAjt/xwDjxq7laXQhE niA+6EUbNQ5tpjISZ1LpNfqaOH9Am1liY8E4PmvBmYPKigMEp3sJ0fRxerdYHJRKAl iaj1zPmG+AiOpyLCa6/Nvbp08MMQbTBYxlvHR84c= X-Mailer: git-send-email 2.37.3 X-Poly-FromMTA: (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) at Sun, 16 Oct 2022 15:36:05 +0000 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.io gmane.lisp.guile.bugs:10406 Archived-At: From: Olivier Dion 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