From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Olivier Dion Newsgroups: gmane.lisp.guile.bugs Subject: bug#61058: [PATCH v2] Fix asymetric mutex locking when joining thread. Date: Thu, 25 Jan 2024 16:45:47 -0500 Message-ID: <20240125214547.3951-1-olivier.dion@polymtl.ca> References: <20230125152403.19091-1-olivier.dion@polymtl.ca> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10963"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Olivier Dion To: 61058@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Thu Jan 25 22:47:12 2024 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 1rT7Z2-0002ez-Ig for guile-bugs@m.gmane-mx.org; Thu, 25 Jan 2024 22:47:12 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rT7Yp-0000Ng-3e; Thu, 25 Jan 2024 16:46:59 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rT7Ym-0000NW-MP for bug-guile@gnu.org; Thu, 25 Jan 2024 16:46:56 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rT7Ym-0005ft-EX for bug-guile@gnu.org; Thu, 25 Jan 2024 16:46:56 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rT7Ys-0002IU-FZ for bug-guile@gnu.org; Thu, 25 Jan 2024 16:47:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <20230125152403.19091-1-olivier.dion@polymtl.ca> Resent-From: Olivier Dion Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Thu, 25 Jan 2024 21:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61058 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch Original-Received: via spool by 61058-submit@debbugs.gnu.org id=B61058.17062191818771 (code B ref 61058); Thu, 25 Jan 2024 21:47:02 +0000 Original-Received: (at 61058) by debbugs.gnu.org; 25 Jan 2024 21:46:21 +0000 Original-Received: from localhost ([127.0.0.1]:49386 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rT7YD-0002HO-6k for submit@debbugs.gnu.org; Thu, 25 Jan 2024 16:46:21 -0500 Original-Received: from smtp.polymtl.ca ([132.207.4.11]:42238) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rT7Y9-0002H8-Cd for 61058@debbugs.gnu.org; Thu, 25 Jan 2024 16:46:19 -0500 Original-Received: from localhost.localdomain ([209.209.33.206]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 40PLjm1w021781 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Jan 2024 16:46:03 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 40PLjm1w021781 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1706219164; bh=7WwaDCmPrcl8necQkPdQHz37zwCwVUgZEFMSKlmnVRI=; h=From:To:Cc:Subject:Date:From; b=XuoroXu0q2YZ/wI8jEw19pRLt9KioXwSzoag823Jbpm/UlnJBXRj4jbbOiUhtSy+3 l7vQbspvDqzeIHbbnFrs38bUepUN4PRVu2jtppQfpKpulYPIbXMEv6lL65Tx2dYUzj bitFVSZ99a0ZIqUmV1A/NWW5iep9Ed5Q68+tzOqo= X-Mailer: git-send-email 2.41.0 X-Poly-FromMTA: ([209.209.33.206]) at Thu, 25 Jan 2024 21:45:48 +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-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:10770 Archived-At: 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