help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Async process sentinel running exclusively in main thread?


From: Eli Zaretskii
Subject: Re: Async process sentinel running exclusively in main thread?
Date: Mon, 20 Jun 2022 14:23:48 +0300

> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]