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#25265: make-thread crashes in OS X 10.6 Date: Sat, 31 Dec 2016 11:20:34 +0200 Message-ID: <83vau0h2u5.fsf@gnu.org> References: <20161226130917.GA36471@breton.holly.idiocy.org> <8337hay9fl.fsf@gnu.org> <20161226205632.GA36805@breton.holly.idiocy.org> <83k2alx20b.fsf@gnu.org> <20161227104424.GA45039@breton.holly.idiocy.org> <83bmvxwrp4.fsf@gnu.org> <20161228193633.GA47290@breton.holly.idiocy.org> <83vau2u0a1.fsf@gnu.org> <20161230184532.GA3754@breton.holly.idiocy.org> <83pok9ruop.fsf@gnu.org> <20161230220544.GA4775@breton.holly.idiocy.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1483176073 8878 195.159.176.226 (31 Dec 2016 09:21:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 31 Dec 2016 09:21:13 +0000 (UTC) Cc: charles@aurox.ch, 25265@debbugs.gnu.org To: Alan Third Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Dec 31 10:21:09 2016 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 1cNFqc-0001Xu-Ls for geb-bug-gnu-emacs@m.gmane.org; Sat, 31 Dec 2016 10:21:06 +0100 Original-Received: from localhost ([::1]:43092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cNFqh-000504-I6 for geb-bug-gnu-emacs@m.gmane.org; Sat, 31 Dec 2016 04:21:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42435) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cNFqb-0004zj-9I for bug-gnu-emacs@gnu.org; Sat, 31 Dec 2016 04:21:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cNFqX-0004FN-VF for bug-gnu-emacs@gnu.org; Sat, 31 Dec 2016 04:21:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45448) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cNFqX-0004FJ-SF for bug-gnu-emacs@gnu.org; Sat, 31 Dec 2016 04:21:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cNFqX-0004GI-Mw for bug-gnu-emacs@gnu.org; Sat, 31 Dec 2016 04:21:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 31 Dec 2016 09:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25265 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 25265-submit@debbugs.gnu.org id=B25265.148317604416351 (code B ref 25265); Sat, 31 Dec 2016 09:21:01 +0000 Original-Received: (at 25265) by debbugs.gnu.org; 31 Dec 2016 09:20:44 +0000 Original-Received: from localhost ([127.0.0.1]:60847 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cNFqG-0004Ff-AQ for submit@debbugs.gnu.org; Sat, 31 Dec 2016 04:20:44 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:51427) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cNFqF-0004FS-A4 for 25265@debbugs.gnu.org; Sat, 31 Dec 2016 04:20:43 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cNFq6-000457-Lw for 25265@debbugs.gnu.org; Sat, 31 Dec 2016 04:20:37 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:44640) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cNFq6-00044y-Bq; Sat, 31 Dec 2016 04:20:34 -0500 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:3929 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1cNFq5-0008LJ-GQ; Sat, 31 Dec 2016 04:20:34 -0500 In-reply-to: <20161230220544.GA4775@breton.holly.idiocy.org> (message from Alan Third on Fri, 30 Dec 2016 22:05:44 +0000) 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:127618 Archived-At: > Date: Fri, 30 Dec 2016 22:05:44 +0000 > From: Alan Third > Cc: charles@aurox.ch, 25265@debbugs.gnu.org > > > > Am I right in thinking that raising SIGIO will cause ns_read_socket to > > > be potentially run immediately? Asynchronously? > > > > I very much hope not. We don't run any non-trivial code from a signal > > handler. I'd expect SIGIO just to set a flag, and then the resulting > > input be processed when we call unblock_input next time, and the > > blocking level gets to zero. Then we run process_pending_signals, > > which calls handle_async_input, and that's where ns_read_socket will > > be called by gobble_input. > > OK. I am, again, none the wiser. Don't give up ;-) > > > So, my plan of action: > > > > > > Run [NSApp run] in it’s own thread with no flow control (unless it’s > > > important that emacs events are only created at specific times?) > > > > How will that thread communicate the events to Emacs? > > I’m hoping using the same method as it does now. It creates emacs > events from the NS events, and then fires SIGIO. > > I have run into a problem almost right away, though. I don’t know how > to go about creating this thread. > > The NSApp loop needs to run in the ‘main’ thread on macOS. I > understand the main thread is always the original thread, so if I want > to use it for the NSApp loop, I need to move Emacs’ normal operation > into a child thread. How about a more modest goal instead? The code in ns_select can detect when it is run by the main thread: we have a function, main_thread_p, for that. (For it to work, you need to pass current_thread to it, so we will have to make sure the first part of ns_select, up to the pselect call, is run with the global lock owned by a single thread. The easiest way of achieving that is to do for ns_select the same change I did yesterday for xg_select: call ns_select directly in process.c:wait_reading_process_output, then change ns_select to call thread_select instead of pselect.) When ns_select detects it's run by a non-main thread, it will only call thread_select and return its result. Otherwise, it will call thread_select with a very small timeout and with NULL descriptor sets (to let other threads an opportunity to run, and when that returns, do the [NSApp run] dance with the surrounding code. Note that the latter runs after the main thread has re-acquired the global lock, so no other Lisp threads could be active at that point. Would that work? Thanks.