From unknown Sat Aug 09 04:58:20 2025 X-Loop: help-debbugs@gnu.org Subject: bug#61058: [PATCH] Fix asymetric mutex locking when joining thread. Resent-From: Olivier Dion Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 25 Jan 2023 15:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 61058 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch To: 61058@debbugs.gnu.org Cc: Olivier Dion X-Debbugs-Original-To: bug-guile@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.167466026620460 (code B ref -1); Wed, 25 Jan 2023 15:25:02 +0000 Received: (at submit) by debbugs.gnu.org; 25 Jan 2023 15:24:26 +0000 Received: from localhost ([127.0.0.1]:59746 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pKhdS-0005Jw-9j for submit@debbugs.gnu.org; Wed, 25 Jan 2023 10:24:26 -0500 Received: from lists.gnu.org ([209.51.188.17]:37778) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pKhdP-0005Jn-F5 for submit@debbugs.gnu.org; Wed, 25 Jan 2023 10:24:25 -0500 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 1pKhdP-0002dS-4c for bug-guile@gnu.org; Wed, 25 Jan 2023 10:24:23 -0500 Received: from smtp.polymtl.ca ([132.207.4.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pKhdN-0001uB-AL for bug-guile@gnu.org; Wed, 25 Jan 2023 10:24:22 -0500 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 30PFO5PX010501 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 25 Jan 2023 10:24:13 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 30PFO5PX010501 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1674660253; bh=a/6GKZx5jbVAr7is9eGijC9lvf/MdFcCrlfMf5SQdnU=; h=From:To:Cc:Subject:Date:From; b=ldg+eXddRyMkq7QjjABwHZ704cK4Ujck5zheVacaDe3KJIHfUiv6xjFKpNb4YV8qW w2IdiKLwhS6tlZo0VM/GGmy6JaVb/TZyOJ6qhMr7OrbS8JJmBFMmdQ7C8pXW83Hzmx B2PD23R76hRuITtav6hoVdUfzOCHYlRZqZfVEnAQ= From: Olivier Dion Date: Wed, 25 Jan 2023 10:24:03 -0500 Message-Id: <20230125152403.19091-1-olivier.dion@polymtl.ca> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) at Wed, 25 Jan 2023 15:24:05 +0000 Received-SPF: pass client-ip=132.207.4.11; envelope-from=olivier.dion@polymtl.ca; helo=smtp.polymtl.ca X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) From: Olivier Dion 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 From unknown Sat Aug 09 04:58:20 2025 X-Loop: help-debbugs@gnu.org Subject: bug#61058: [PATCH v2] Fix asymetric mutex locking when joining thread. References: <20230125152403.19091-1-olivier.dion@polymtl.ca> 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 To: 61058@debbugs.gnu.org Cc: Olivier Dion Received: via spool by 61058-submit@debbugs.gnu.org id=B61058.17062191818771 (code B ref 61058); Thu, 25 Jan 2024 21:47:02 +0000 Received: (at 61058) by debbugs.gnu.org; 25 Jan 2024 21:46:21 +0000 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 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 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= From: Olivier Dion Date: Thu, 25 Jan 2024 16:45:47 -0500 Message-ID: <20240125214547.3951-1-olivier.dion@polymtl.ca> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: ([209.209.33.206]) at Thu, 25 Jan 2024 21:45:48 +0000 X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) 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 From unknown Sat Aug 09 04:58:20 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Olivier Dion Subject: bug#61058: closed (Re: bug#61058: [PATCH v2] Fix asymetric mutex locking when joining thread.) Message-ID: References: <87fryloybh.fsf@gnu.org> <20230125152403.19091-1-olivier.dion@polymtl.ca> X-Gnu-PR-Message: they-closed 61058 X-Gnu-PR-Package: guile X-Gnu-PR-Keywords: patch Reply-To: 61058@debbugs.gnu.org Date: Thu, 25 Jan 2024 22:15:03 +0000 Content-Type: multipart/mixed; boundary="----------=_1706220903-12592-1" This is a multi-part message in MIME format... ------------=_1706220903-12592-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #61058: [PATCH] Fix asymetric mutex locking when joining thread. which was filed against the guile package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 61058@debbugs.gnu.org. --=20 61058: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D61058 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1706220903-12592-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 61058-done) by debbugs.gnu.org; 25 Jan 2024 22:14:45 +0000 Received: from localhost ([127.0.0.1]:49467 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rT7zg-0003Fg-Ku for submit@debbugs.gnu.org; Thu, 25 Jan 2024 17:14:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37682) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rT7ze-0003FK-1x; Thu, 25 Jan 2024 17:14:42 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rT7zR-0004EO-VF; Thu, 25 Jan 2024 17:14:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=qA4emFfGALbTPqbv81dwRT5Mcf7Zi17e1aebEF+bpiM=; b=iO0inLt2ijbjUTaIQToa 6kqnNgtsPXUiwPnlFFvxePO/xODT/9PCvWN4Dj6zbf/v3lWPF1ZBxokUKEWzdZBpEKBsbX754PAW7 2SMtm+zjCQMA78m/cxCoVQH2VogoON0uSazhE7jTxcA3/m3BPYNkphYD6o264lFcYW7RxCb0Xpmry clC/3UzsSo1TIIgyLkkSq7PIakFWZVkXzSuqpHxddeI1sy0d9ZmmSqeU0y5XyRbe7GG0fDlla+M1i THuz97hxz+CJOjOi8SMCfICUGCD63YwmAo85hc+NvRGj7OnkgpnmnNsJril7U6k+Z8ov+RL760TX1 wsFFpfkUWjVqGg==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Olivier Dion Subject: Re: bug#61058: [PATCH v2] Fix asymetric mutex locking when joining thread. In-Reply-To: <20240125214547.3951-1-olivier.dion@polymtl.ca> (Olivier Dion's message of "Thu, 25 Jan 2024 16:45:47 -0500") References: <20230125152403.19091-1-olivier.dion@polymtl.ca> <20240125214547.3951-1-olivier.dion@polymtl.ca> Date: Thu, 25 Jan 2024 23:14:26 +0100 Message-ID: <87fryloybh.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 61058-done Cc: 55356-done@debbugs.gnu.org, 61058-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hello, Olivier Dion 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 =E2=80=98NEWS=E2= =80=99 entry and an additional comment in the test. Thanks! Ludo=E2=80=99. ------------=_1706220903-12592-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 25 Jan 2023 15:24:26 +0000 Received: from localhost ([127.0.0.1]:59746 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pKhdS-0005Jw-9j for submit@debbugs.gnu.org; Wed, 25 Jan 2023 10:24:26 -0500 Received: from lists.gnu.org ([209.51.188.17]:37778) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pKhdP-0005Jn-F5 for submit@debbugs.gnu.org; Wed, 25 Jan 2023 10:24:25 -0500 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 1pKhdP-0002dS-4c for bug-guile@gnu.org; Wed, 25 Jan 2023 10:24:23 -0500 Received: from smtp.polymtl.ca ([132.207.4.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pKhdN-0001uB-AL for bug-guile@gnu.org; Wed, 25 Jan 2023 10:24:22 -0500 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 30PFO5PX010501 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 25 Jan 2023 10:24:13 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 30PFO5PX010501 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1674660253; bh=a/6GKZx5jbVAr7is9eGijC9lvf/MdFcCrlfMf5SQdnU=; h=From:To:Cc:Subject:Date:From; b=ldg+eXddRyMkq7QjjABwHZ704cK4Ujck5zheVacaDe3KJIHfUiv6xjFKpNb4YV8qW w2IdiKLwhS6tlZo0VM/GGmy6JaVb/TZyOJ6qhMr7OrbS8JJmBFMmdQ7C8pXW83Hzmx B2PD23R76hRuITtav6hoVdUfzOCHYlRZqZfVEnAQ= From: Olivier Dion To: bug-guile@gnu.org Subject: [PATCH] Fix asymetric mutex locking when joining thread. Date: Wed, 25 Jan 2023 10:24:03 -0500 Message-Id: <20230125152403.19091-1-olivier.dion@polymtl.ca> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) at Wed, 25 Jan 2023 15:24:05 +0000 Received-SPF: pass client-ip=132.207.4.11; envelope-from=olivier.dion@polymtl.ca; helo=smtp.polymtl.ca X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit Cc: Olivier Dion X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) From: Olivier Dion 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 ------------=_1706220903-12592-1--