From debbugs-submit-bounces@debbugs.gnu.org Tue May 10 22:29:32 2022 Received: (at submit) by debbugs.gnu.org; 11 May 2022 02:29:32 +0000 Received: from localhost ([127.0.0.1]:35498 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1noc6W-0006ac-Gs for submit@debbugs.gnu.org; Tue, 10 May 2022 22:29:32 -0400 Received: from lists.gnu.org ([209.51.188.17]:35440) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1noc6U-0006aU-6x for submit@debbugs.gnu.org; Tue, 10 May 2022 22:29:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49140) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1noc6R-0000mv-M1 for bug-guile@gnu.org; Tue, 10 May 2022 22:29:28 -0400 Received: from [37.120.193.124] (port=49282 helo=mail.cock.li) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1noc6P-0003YK-MK for bug-guile@gnu.org; Tue, 10 May 2022 22:29:27 -0400 User-agent: mu4e 1.6.10; emacs 29.0.50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cock.li; s=mail; t=1652235737; bh=027FYw3lkBaPefuydTF2ohRN/L2gILiDhca9dtKQXks=; h=From:To:Subject:Date:From; b=IC4p8KmC/Oz2Z7hkcg4txXp+XXhTiQoTJi8C0kspBuMFH4GLD0BBt9QlwQ3Hz8HrP 4mkvs+YzPbas5CD14tl7EGA2CguZpLcFE8wmZZ3jyAtDjsB053pMzCsqDmn6tFpCBM ihzJ3Psp0Gu0YVYXB56d7v5oAT4tjbt/EM8kByGuNPLwVEgf/rAJH5qRHQrSc/KKfq 2lkqaAw5GvVXGKsu5XfqyJpqSDH3V8dVoAYLCS+mQKRvMkq2UXOE3gxSXRfTja6nH3 SqWyrqbHJTPjZK8nanjM3K7svg71KGtPA20fDBVI0vU/uaFM0ViAcS1gluOO6AZNtN zGn8BY4KnvCnA== From: angry rectangle To: bug-guile@gnu.org Subject: join-thread unusable if timeout was hit Date: Tue, 10 May 2022 20:42:03 -0400 Message-ID: <87fslgg65p.fsf@cock.li> MIME-Version: 1.0 Content-Type: text/plain X-Host-Lookup-Failed: Reverse DNS lookup failed for 37.120.193.124 (failed) Received-SPF: pass client-ip=37.120.193.124; envelope-from=angryrectangle@cock.li; helo=mail.cock.li X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit 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.4 (--) 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 From debbugs-submit-bounces@debbugs.gnu.org Sun Oct 16 11:36:27 2022 Received: (at 55356) by debbugs.gnu.org; 16 Oct 2022 15:36:27 +0000 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 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 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= From: Olivier Dion To: 55356@debbugs.gnu.org Subject: [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> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) at Sun, 16 Oct 2022 15:36:05 +0000 X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 55356 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 (---) 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 From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 25 17:14:44 2024 Received: (at 55356-done) by debbugs.gnu.org; 25 Jan 2024 22:14:44 +0000 Received: from localhost ([127.0.0.1]:49465 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rT7zg-0003Fb-AN for submit@debbugs.gnu.org; Thu, 25 Jan 2024 17:14:44 -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: 55356-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 Thu Aug 14 21:54:34 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