From unknown Mon Jun 16 23:39:35 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#61058 <61058@debbugs.gnu.org> To: bug#61058 <61058@debbugs.gnu.org> Subject: Status: [PATCH] Fix asymetric mutex locking when joining thread. Reply-To: bug#61058 <61058@debbugs.gnu.org> Date: Tue, 17 Jun 2025 06:39:35 +0000 retitle 61058 [PATCH] Fix asymetric mutex locking when joining thread. reassign 61058 guile submitter 61058 Olivier Dion severity 61058 normal tag 61058 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 25 10:24:26 2023 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 From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 25 16:46:21 2024 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 To: 61058@debbugs.gnu.org Subject: [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> 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-Debbugs-Envelope-To: 61058 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: -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 debbugs-submit-bounces@debbugs.gnu.org Thu Jan 25 17:14:45 2024 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. From unknown Mon Jun 16 23:39:35 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Fri, 23 Feb 2024 12:24:12 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator