all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Swapneil Singh <swapneil.singh@gmail.com>
Cc: 73131@debbugs.gnu.org
Subject: bug#73131: 28.2; Yielded threads get killed on C-g
Date: Mon, 09 Sep 2024 15:22:48 +0300	[thread overview]
Message-ID: <861q1tvwx3.fsf@gnu.org> (raw)
In-Reply-To: <CANpN7avxL3f6TOV5XkjO8+Sa21dWO_vco1VdOyDeoKU6j-oohQ@mail.gmail.com> (message from Swapneil Singh on Sun, 8 Sep 2024 12:08:00 -0400)

> From: Swapneil Singh <swapneil.singh@gmail.com>
> 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.





  parent reply	other threads:[~2024-09-09 12:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-08 16:08 bug#73131: 28.2; Yielded threads get killed on C-g Swapneil Singh
2024-09-09  6:47 ` Andrea Corallo
2024-09-09 12:22 ` Eli Zaretskii [this message]
2024-09-10  5:45   ` Swapneil Singh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=861q1tvwx3.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=73131@debbugs.gnu.org \
    --cc=swapneil.singh@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.