From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#25214: 26.0.50; Interacting with user from threads other than the primary Date: Mon, 17 Sep 2018 21:41:47 +0300 Message-ID: <83fty8ge50.fsf@gnu.org> References: <837f6z9a4x.fsf@gnu.org> <87zhwguskw.fsf@gmx.de> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1537209676 22144 195.159.176.226 (17 Sep 2018 18:41:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 17 Sep 2018 18:41:16 +0000 (UTC) Cc: 25214@debbugs.gnu.org, tom@tromey.com To: Michael Albinus Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Sep 17 20:41:12 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1g1ySM-0005aO-6z for geb-bug-gnu-emacs@m.gmane.org; Mon, 17 Sep 2018 20:41:10 +0200 Original-Received: from localhost ([::1]:37008 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1yUS-0001kU-SS for geb-bug-gnu-emacs@m.gmane.org; Mon, 17 Sep 2018 14:43:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1yUL-0001kK-UM for bug-gnu-emacs@gnu.org; Mon, 17 Sep 2018 14:43:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g1yUG-0005W9-DR for bug-gnu-emacs@gnu.org; Mon, 17 Sep 2018 14:43:13 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39099) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g1yUB-0005UB-B2 for bug-gnu-emacs@gnu.org; Mon, 17 Sep 2018 14:43:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1g1yUB-0004F0-7A for bug-gnu-emacs@gnu.org; Mon, 17 Sep 2018 14:43:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 17 Sep 2018 18:43:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25214 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 25214-submit@debbugs.gnu.org id=B25214.153720974816202 (code B ref 25214); Mon, 17 Sep 2018 18:43:03 +0000 Original-Received: (at 25214) by debbugs.gnu.org; 17 Sep 2018 18:42:28 +0000 Original-Received: from localhost ([127.0.0.1]:43352 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g1yTb-0004DG-UB for submit@debbugs.gnu.org; Mon, 17 Sep 2018 14:42:28 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:46744) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g1yTa-0004D0-Hg for 25214@debbugs.gnu.org; Mon, 17 Sep 2018 14:42:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g1yTR-0003Vz-3q for 25214@debbugs.gnu.org; Mon, 17 Sep 2018 14:42:21 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:55544) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1yTA-0003Dr-Kz; Mon, 17 Sep 2018 14:42:00 -0400 Original-Received: from [176.228.60.248] (port=4309 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1g1yT8-0005CE-Tk; Mon, 17 Sep 2018 14:42:00 -0400 In-reply-to: <87zhwguskw.fsf@gmx.de> (message from Michael Albinus on Mon, 17 Sep 2018 16:06:07 +0200) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:150378 Archived-At: > From: Michael Albinus > Cc: 25214@debbugs.gnu.org, Tom Tromey > Date: Mon, 17 Sep 2018 16:06:07 +0200 > > The fd mask is controlled by fd_callback_info, an array (indexed by > fd's) over the struct fd_callback_data. There are two relevant struct > fields: thread and waiting_thread. thread is set in Fset_process_thread > for the infd and outfd file descriptors of the process, it shall be NULL > in the example given above. > > waiting_thread is always set to current_thread, in the > compute_input_wait_mask, compute_non_process_wait_mask, > compute_non_keyboard_wait_mask and compute_write_mask functions. The > condition is always, that waiting_thread is either NULL or > current_thread. > > A file descriptor, be it for the keyboard or process related or > whatever, is only taken into account during setting an fd_mask, when > either both thread and waiting_thread are NULL, or when one of the > struct fields is set to a thread, being equal to the current > thread. IIUC, thead has precedence over waiting_thread, but this might > be an implementation detail only. So far, it is expected that at least > one of the fields is NULL. That is correct, AFAIR. > In order to fix the problem of reading input in a non-primary thread, we > need a new function which request I/O control to the current thread. It > needs > > * to request control for the keyboard. This could be indicated by a > signal to the main thread, which is *not* an error signal but a > special one, let's call it `thread-set-keyboard'. > > * to handle this signal in `thread-handle-event', by calling a > respective function (let's call it `thread--set-keyboard'). This > function sets the struct event thread to the thread which has > delivered by the `thread-set-keyboard' signal. Next time fd_mask is > prepared, the keyboard fd would be taken into account for the > requesting thread. > > * to stop/recall the recent pselect for the main thread in order to free > the keyboard fd. Don't know how to do this. > > * to provide a mechanism which resets the thread struct field of the > keyboard fd to NULL, in order to let the main thread use the > keyboard. Here I have also no idea how to do this. It's not all we need (remember all that talk about serializing access to the echo area?), but it's a beginning. And the crucial piece is bullet #3, because thread-signal will not interrupt the pselect call. And if we are not too lucky, the pselect call could have been made with a long timeout. So this is the first obstacle to negotiate. So what means do we have to interrupt a pselect call from another thread? (I'm not sure I understand why you thought we'd need bullet #2, btw. Once we interrupt the pselect call, the main thread should become stuck trying to take the global lock, so I don't think we need any trickery here, because the other thread, which is running, will have arranged for it to be the current thread.) Thanks.