unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Async process sentinel running exclusively in main thread?
Date: Mon, 20 Jun 2022 14:23:48 +0300	[thread overview]
Message-ID: <83edzjmvcr.fsf@gnu.org> (raw)
In-Reply-To: <8735fzbu7r.fsf@alternativebit.fr> (message from Félix Baylac Jacqué on Mon, 20 Jun 2022 10:43:52 +0200)

> From: Félix Baylac Jacqué <felix@alternativebit.fr>
> Date: Mon, 20 Jun 2022 10:43:52 +0200
> 
> As you can see, while the run-async-process and the run-wait-process
> functions are each living in their own threads, but the sentinel ends up
> running in the main thread instead of the run-wait-process one!?
> 
> Surprising. That explains the deadlock origin though.
> 
> I couldn't find any mention of the fact that the sentinel function will
> exclusively run in the main thread in the documentation. Regardless of
> the thread in which the process is actually executed.
> 
> Which makes me wonder:
> 
> Is this a bug or is this an expected behavior?

Expected behavior (more or less).

Sentinel runs when Emacs receives SIGCHLD due to the process's demise.
And on Posix systems, signals in Emacs are always delivered to the
main thread, because doing that in a non-main thread is unsafe (the
thread could be exiting, for example).

(The "more or less" part is because we back up the SIGCHLD mechanism
by using a self-pipe that also notifies 'pselect' that the process
died, so that 'pselect' won't wait forever in some corner cases.)

> In case it is an expected behavior, is there any way to wait for a
> subprocess to be done in the main thread using a condition variable
> without deadlocking Emacs?

Make the process output something, and wait on its output?

Btw, Emacs has a way of causing a process to be dedicated to a thread
(which AFAIU you didn't do in your code).



  reply	other threads:[~2022-06-20 11:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20  8:43 Async process sentinel running exclusively in main thread? Félix Baylac Jacqué
2022-06-20 11:23 ` Eli Zaretskii [this message]
2022-06-21  6:03   ` Félix Baylac Jacqué
2022-06-21  6:29     ` Emanuel Berg

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=83edzjmvcr.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).