From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Helmut Eller Newsgroups: gmane.emacs.bugs Subject: bug#64819: 30.0.50; condition-wait not interruptible Date: Mon, 24 Jul 2023 16:57:05 +0200 Message-ID: References: <83pm4hse6n.fsf@gnu.org> <838rb5saau.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37897"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 64819@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jul 24 16:58:20 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1qNx0t-0009iL-HW for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 24 Jul 2023 16:58:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qNx0e-0001XB-9Q; Mon, 24 Jul 2023 10:58:04 -0400 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 1qNx0c-0001X2-Rx for bug-gnu-emacs@gnu.org; Mon, 24 Jul 2023 10:58:02 -0400 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 1qNx0c-00040d-Ig for bug-gnu-emacs@gnu.org; Mon, 24 Jul 2023 10:58:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qNx0c-000270-ET for bug-gnu-emacs@gnu.org; Mon, 24 Jul 2023 10:58:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Helmut Eller Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 24 Jul 2023 14:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64819 X-GNU-PR-Package: emacs Original-Received: via spool by 64819-submit@debbugs.gnu.org id=B64819.16902106378049 (code B ref 64819); Mon, 24 Jul 2023 14:58:02 +0000 Original-Received: (at 64819) by debbugs.gnu.org; 24 Jul 2023 14:57:17 +0000 Original-Received: from localhost ([127.0.0.1]:43774 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qNwzs-00025l-GR for submit@debbugs.gnu.org; Mon, 24 Jul 2023 10:57:16 -0400 Original-Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]:55780) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qNwzp-00025U-En for 64819@debbugs.gnu.org; Mon, 24 Jul 2023 10:57:14 -0400 Original-Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4fddd4e942eso6265432e87.3 for <64819@debbugs.gnu.org>; Mon, 24 Jul 2023 07:57:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690210627; x=1690815427; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=ts8r9MKNvcAm2L8n0yT2T3Vwr2RoBW1152sGRqSwWCM=; b=Rf/0O6AJeu2ZhWS//T3Ibykljqr7/j7NB5aWeuAfkd4qyuULJDDh/MPgm6ROQTU5RK BtvxBoyzP2Kul1a/5MGjhP361gtSbTa4Tb7S+J8aqXzTlZSuF1vonYnoGDKZHpTo0JO1 wvffzNxJi+ibX+sb9MzABnNxIG4fBVCii21RquAvsrOT5GYtOKMQrn1sTOxcXUkHRQhg WS+4SGB3Y33wJe6HFg3ZqtZbkfd0MiAZ8KPyYtB26Cwkn6e9To3E3HZHC2rGrd9Ty/wH SwHyEdn/ONix1s5/Zt8Afq7TpBQ7sMi4OG4ElrhNhEC7xHjASa6Hm9Iyqd2F+HTKdJ9T 0lSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690210627; x=1690815427; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ts8r9MKNvcAm2L8n0yT2T3Vwr2RoBW1152sGRqSwWCM=; b=gVSFTS3XeAAml+cqM2CD39z7/cCdQq+Nza7cvwqMauSxouNVGsoaT+V1gKFmyvb70T Qvf5nFHSLtRq2g3SlebgsgtwwBdfKYyKdyWzTDbEGzfT2gzgQG2xUKur9LIw4XnCv0a+ RJJ40gy9178YI/fhHzPk1T4pbdA4fBMGD4NjDt/6zFr9+dPgPGdteRK9mWsyj+b4oi1M SDVgVVfpN+JlOqyCwtynmIWnbktJgb3jo1oWxEAhnzcCupqzTz0QGco1s9+NLxvwCp1w 3NhX75cYQD6hBKVRzkXA5bmvv8jhF0cq8pXUpmWq68T+92tHC7gX9N3HdUmx1tiHPYIm 4trQ== X-Gm-Message-State: ABy/qLY8IeowfzaQivzmPERAjxh2HGsYvWItiNlWVlXH8Cca62PBbywO TUP9NJlva2GBb6p/z4WCHf3HlG3Ey8k= X-Google-Smtp-Source: APBJJlGt5HYPgDX8POBPiv1MMZ+kQgDmSURUZnnTKtNrYAlIBveYaZrD60Ql5g3sNnbTJdMk6SaKLw== X-Received: by 2002:a05:6512:468:b0:4f8:ff52:93b7 with SMTP id x8-20020a056512046800b004f8ff5293b7mr4568991lfd.30.1690210627027; Mon, 24 Jul 2023 07:57:07 -0700 (PDT) Original-Received: from caladan ([212.46.176.29]) by smtp.gmail.com with ESMTPSA id f14-20020a7bcd0e000000b003fc01f7b415sm13372897wmj.39.2023.07.24.07.57.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 07:57:06 -0700 (PDT) In-Reply-To: <838rb5saau.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 24 Jul 2023 16:34:17 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:265976 Archived-At: On Mon, Jul 24 2023, Eli Zaretskii wrote: >> From: Helmut Eller >> We could say that C-g sets quit-flag and causes all blocking calls to >> condition-wait to return nil (spurious wakeup). At that point all >> threads are conceptually running. Then the first thread (unspecified >> which one) who calls maybe_quit() finishes handling C-g and clears >> quit-flag afterwards. Those threads who don't feel prepared to handle >> C-g can bind inhibit-quit. > > I don't think we can allow more than one thread at a time to run the > parts of the Lisp interpreter that lead to maybe_quit. I didn't suggest that. Nor did I suggest that the thread scheduler should switch away from the currently running thread. What I did suggest is that the thread blocked in condition-wait is considered runnable. So that the thread scheduler is allowed to pick this thread the next time when somebody calls thread-yield or condition-wait. To the thread it will look like a spurious wakeup (i.e. condition-wait returned but the condition isn't actually true) but Lisp code must already be prepared for such a situation. The bytecode interpreter calls maybe_quit before every call or backward branch, so maybe_quit will be called very soon after the spurious wakeup. > Also, I don't think what you describe, even if it were possible, is > what users expect: they expect that the thread which is running is > interrupted, and either exits or handles the quit, and all the other > threads still wait for the condition var. Maybe we can agree on this: when only one thread exists and it is blocked in condition-wait, then condition-wait should be interruptible by C-g. For the situation where some threads are blocked in condition-wait and one other thread is running, I think that running thread would call maybe_quit and clear quite-flag before calling thread-yield. The other threads would observe spurious wakeups as soon as they are allowed to run. > So I think to do anything smarter in the deadlock situation you > describe we'd need to detect the deadlock first. Once we do that > (which isn't easy: perhaps do that in the signal handler?), we'd need > to decide which of the deadlocked threads to free, which is also not > trivial. Hmmm... I doubt that deadlock detection is possible in the general case. E.g. how could we possibly know that a timer is or isn't going to call condition-notify in 5 seconds? > Btw, did you try your recipe in a Unix TTY? There, C-g actually > delivers SIGINT to Emacs, so you might see a different behavior (or a > crash ;-). When I run the recipe with: "emacs -nw -l deadlock.el -f deadlock" then I see the emergency escape feature kick in. Only after the second C-g (of course). A single C-g doesn't seem to do anything. Helmut