From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: Delivering SIGIO when several threads are active? Date: Fri, 30 Dec 2016 09:54:01 -0800 Organization: UCLA Computer Science Department Message-ID: <8e01d8c5-66fa-fcb8-ef0e-74ca10a72317@cs.ucla.edu> References: <8360m1u311.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------91E7A8AEF1EF95BC171087D3" X-Trace: blaine.gmane.org 1483120464 21225 195.159.176.226 (30 Dec 2016 17:54:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 30 Dec 2016 17:54:24 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 To: Eli Zaretskii , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Dec 30 18:54:20 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cN1Nh-0004iQ-CO for ged-emacs-devel@m.gmane.org; Fri, 30 Dec 2016 18:54:17 +0100 Original-Received: from localhost ([::1]:40983 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cN1Nm-0004Ft-C1 for ged-emacs-devel@m.gmane.org; Fri, 30 Dec 2016 12:54:22 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cN1Nf-0004Ew-F4 for emacs-devel@gnu.org; Fri, 30 Dec 2016 12:54:16 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cN1Ne-0008R7-B7 for emacs-devel@gnu.org; Fri, 30 Dec 2016 12:54:15 -0500 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:36446) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cN1Na-0008Fh-Cm; Fri, 30 Dec 2016 12:54:10 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id E744D160157; Fri, 30 Dec 2016 09:54:06 -0800 (PST) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id TnEuhCuRcdJx; Fri, 30 Dec 2016 09:54:06 -0800 (PST) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 10192160159; Fri, 30 Dec 2016 09:54:06 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id OeDTAvokJtbo; Fri, 30 Dec 2016 09:54:05 -0800 (PST) Original-Received: from [192.168.1.9] (unknown [47.153.178.162]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id E389B160157; Fri, 30 Dec 2016 09:54:05 -0800 (PST) In-Reply-To: <8360m1u311.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 131.179.128.68 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:211000 Archived-At: This is a multi-part message in MIME format. --------------91E7A8AEF1EF95BC171087D3 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Eli Zaretskii wrote: > When SIGIO is received by some thread, we currently deliver it to the > main thread, see deliver_input_available_signal and > deliver_process_signal. Is that appropriate when more than one thread > is active? Such signals have been delivered to the main thread for quite some time, = and=20 this has worked well enough; is there something different about the concu= rrency=20 code that now makes this behavior inappropriate? > The SIGIO handler just sets a global variable, so the > handler itself is okay, I think, but is it okay to interrupt the main > thread with SIGIO at some arbitrary point? E.g., the main thread > could be in some Xlib or GTK call. These library functions are all supposed to work even if such handlers in= terrupt=20 them. > The comments to deliver_process_signal say: > > POSIX says any thread can receive a signal that is > associated with a process, process group, or asynchronous event. > On GNU/Linux that is not true, but for other systems (FreeBSD at > least) it is. > > What does happen on GNU/Linux? Is there a specific thread on > GNU/Linux which gets signals associated with a process? On GNU/Linux, process signals get sent to the main thread unless the main= thread=20 is blocking them (or if a few less-common situations arise, e.g., the mai= n=20 thread is exiting). > And if so, > does this affect what we should do with SIGIO in this case? I don't see why it would affect SIGIO handling. I installed the attached to try to explain this better. Hmm, I see that the recent changes use mixed terminology. Until now, Emac= s has=20 called the initial thread the "main thread", but the recent code sometime= s calls=20 it the "primary thread". We shouldn't have two names for the same thing. = I'll=20 look into fixing that. --------------91E7A8AEF1EF95BC171087D3 Content-Type: text/x-diff; name="0001-src-sysdep.c-deliver_process_signal-Improve-comment.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename*0="0001-src-sysdep.c-deliver_process_signal-Improve-comment.pat"; filename*1="ch" =46rom c971e9141d401a5cf4aae96d981d8eb8a9300ec2 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 30 Dec 2016 09:45:46 -0800 Subject: [PATCH] * src/sysdep.c (deliver_process_signal): Improve comment= =2E --- src/sysdep.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/sysdep.c b/src/sysdep.c index 86d420f..1ba336e 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -1616,14 +1616,17 @@ static pthread_t main_thread; #endif =20 /* SIG has arrived at the current process. Deliver it to the main - thread, which should handle it with HANDLER. + thread, which should handle it with HANDLER. (Delivering the + signal to some other thread might not work if the other thread is + about to exit.) =20 If we are on the main thread, handle the signal SIG with HANDLER. Otherwise, redirect the signal to the main thread, blocking it from this thread. POSIX says any thread can receive a signal that is associated with a process, process group, or asynchronous event. - On GNU/Linux that is not true, but for other systems (FreeBSD at - least) it is. */ + On GNU/Linux the main thread typically gets a process signal unless + it's blocked, but other systems (FreeBSD at least) can deliver the + signal to other threads. */ void deliver_process_signal (int sig, signal_handler_t handler) { --=20 2.7.4 --------------91E7A8AEF1EF95BC171087D3--