From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#73131: 28.2; Yielded threads get killed on C-g Date: Mon, 09 Sep 2024 15:22:48 +0300 Message-ID: <861q1tvwx3.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8977"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 73131@debbugs.gnu.org To: Swapneil Singh Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 09 14:24:26 2024 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 1sndRS-0002D2-27 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 09 Sep 2024 14:24:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sndR5-0007qN-07; Mon, 09 Sep 2024 08:24:03 -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 1sndR2-0007qD-Of for bug-gnu-emacs@gnu.org; Mon, 09 Sep 2024 08:24:00 -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 1sndR0-0007Pj-Vk for bug-gnu-emacs@gnu.org; Mon, 09 Sep 2024 08:24:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:From:Date:To:Subject; bh=J6Q4EponyVgpr0eQqpD1F9SBsUyttx0807HqeCrjGiA=; b=Nqd9ITQmezlCAGW2ZwzTslDC79jZ1LVVP0/FuIyTrO20V7OponGBt7vcyI41wxV3CV5La4i5qfSu6IuHdTBLjY7svhwp6oy38hJUi6NNx+LMyHBb7qLYJuNR9tObSMgKIbeuue0yPjkh3LfS/gxyoWT2wcjhVKH5Nn/h9CjmtdEedEIv+fazwsOE/2heV9onw6CPAgCCSFZv2K0Su8KV1VBwj3u07MQljMB/VgNodadddohAiNEiyDibXZK31ZGAZuzwG46Df44p43XNMt+fSLVdpQjDXoUaB2cn7yNVmCgJVhH3oNFdlfEePijU/38wgp6Ae4AZRW1xH02J0dQAxQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sndR4-000277-Ed for bug-gnu-emacs@gnu.org; Mon, 09 Sep 2024 08:24:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 09 Sep 2024 12:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73131 X-GNU-PR-Package: emacs Original-Received: via spool by 73131-submit@debbugs.gnu.org id=B73131.17258845838028 (code B ref 73131); Mon, 09 Sep 2024 12:24:02 +0000 Original-Received: (at 73131) by debbugs.gnu.org; 9 Sep 2024 12:23:03 +0000 Original-Received: from localhost ([127.0.0.1]:60831 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sndQ6-00025Q-UX for submit@debbugs.gnu.org; Mon, 09 Sep 2024 08:23:03 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:56750) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sndQ5-00024s-Hz for 73131@debbugs.gnu.org; Mon, 09 Sep 2024 08:23:02 -0400 Original-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 1sndPw-0007KX-JV; Mon, 09 Sep 2024 08:22:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=J6Q4EponyVgpr0eQqpD1F9SBsUyttx0807HqeCrjGiA=; b=UOvjnPeU3VF6 JDmcYUTaA6ZJg8PoNO5vQkxbzWTUjCJMuB0kEnw5XEZtT2jmJHkSORrDPrO/sGQb2dBQLeb8Alp5r XPFgMYWhPgthk53pXjL7x9ADd8Z/lgY87ghP08emkPMzPrd9xaJuhvojKxuJt9WBTJ73QFkSELlYd 8oQ0D/gSFQIfIakKJQZlYzZDJY8X4D9gE73+Ew3iUln7rX2qMUJ26s8BiFHGNscT4S3OgPVqxqeyo gyZIe95yTT3nVgNDtLOOKXktsnkVeWhemyBDJjrTjooA6TS+o4zXU1HGMzCqHKzAkYU52u2ZvlAue +Wl2gF5GkXVAjo8aYu5Sxg==; In-Reply-To: (message from Swapneil Singh on Sun, 8 Sep 2024 12:08:00 -0400) 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:291498 Archived-At: > From: Swapneil Singh > Date: Sun, 8 Sep 2024 12:08:00 -0400 > > When using the Emacs cooperative threading system in a new project, I > noticed that calling C-g results in quitting the background thread I > create, even when those threads are yielded. > > Sending this as a bug report per Eli Zaretskii's mention that it may not > be expected behavior > (https://www.reddit.com/r/emacs/comments/1fbkkii/comment/lm3boja/). > > Repro recipe: > - emacs -Q > - `C-x 3` and run `list-threads` in the new window, then return to the > older window > - `M-:` `(make-thread (lambda () (cl-loop while t do (progn > (thread-yield) (sleep-for 30)))))` and wait for the new thread to yield to > the main thread. > - `C-g`. The new thread disappears from the `list-threads` window. > > > Note: While I am admittedly on Windows, given this behavior is within the > cooperative threads of the Emacs runtime (rather than actual Windows > threads) I *really* doubt that has anything to do with it. Actually, your being on MS-Windows does explain what you see, because the way C-g is processed is system-dependent. When I said "this is not supposed to happen", I assumed you were doing this on GNU/Linux or another Posix platform. Indeed, on MS-Windows this is expected behavior: pressing C-g in the above scenario will set the quit-flag, and the loop will then quit. To prevent that, you need to use this simple technique: (make-thread (lambda () (let ((inhibit-quit t)) ;; <<<<<<<<<<<<<<<<<<<< (cl-loop while t do (progn (thread-yield) (sleep-for 30)))))) Btw, my recommendation is to bind inhibit-quit non-nil around the thread functions in all cases, if you want background thread to never be interrupted by C-g and the like.