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.help Subject: Re: Async process sentinel running exclusively in main thread? Date: Mon, 20 Jun 2022 14:23:48 +0300 Message-ID: <83edzjmvcr.fsf@gnu.org> References: <8735fzbu7r.fsf@alternativebit.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35683"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jun 20 13:42:48 2022 Return-path: Envelope-to: geh-help-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 1o3Fnr-00095U-Gt for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 20 Jun 2022 13:42:47 +0200 Original-Received: from localhost ([::1]:54788 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3Fnq-0001m9-4u for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 20 Jun 2022 07:42:46 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38192) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3FVl-0002px-La for help-gnu-emacs@gnu.org; Mon, 20 Jun 2022 07:24:08 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:46222) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3FVk-0004BD-PB for help-gnu-emacs@gnu.org; Mon, 20 Jun 2022 07:24:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=m9JveuvzorUbErNeTXX5sSQLvYPVvY1D5yzLSKdBJB8=; b=Nv8NxltFsSKO7LykcGPS YwKtPezR5yoDamENG/lmY2WgZyVcNMSKfDDRIR3MvPzLkmEZrrGO5lQGuAWwp/2vumD0u39Lc/nm3 4qrltyxBDs17iyl4K93Pj4LrTrCcQ99cfP7L/DUXFkBWhEw/vDzUVmOlqd/9vf2EI4KMRILqCaCvY p5spSKJyMKIJK+2M8GNqPDtN7KU8+MFcJdnDXGxpfEF6RMoJywoalCV/I644UWyt28tI0pHqNorEn JlGaXuvY7OkRAdEXKbX4tLNPFFUXjtOH+ziATq8vyFGiCJ1IbAyjimoWoz43EvLjraIgppJRhMyqC FyELbJgxcK/tNQ==; Original-Received: from [87.69.77.57] (port=4019 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3FVi-00039W-2W for help-gnu-emacs@gnu.org; Mon, 20 Jun 2022 07:24:04 -0400 In-Reply-To: <8735fzbu7r.fsf@alternativebit.fr> (message from =?utf-8?Q?F?= =?utf-8?Q?=C3=A9lix?= Baylac =?utf-8?Q?Jacqu=C3=A9?= on Mon, 20 Jun 2022 10:43:52 +0200) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:137939 Archived-At: > From: Félix Baylac Jacqué > 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).