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: Fri, 30 Dec 2016 23:08:54 +0200 Message-ID: <83pok9ruop.fsf@gnu.org> References: <83r34xxlke.fsf@gnu.org> <83d1ggxayi.fsf@gnu.org> <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> 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 1483132225 26637 195.159.176.226 (30 Dec 2016 21:10:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 30 Dec 2016 21:10:25 +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 Fri Dec 30 22:10:21 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 1cN4RD-0004sm-LU for geb-bug-gnu-emacs@m.gmane.org; Fri, 30 Dec 2016 22:10:07 +0100 Original-Received: from localhost ([::1]:41499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cN4RI-0003Ig-JB for geb-bug-gnu-emacs@m.gmane.org; Fri, 30 Dec 2016 16:10:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cN4RC-0003HO-6Y for bug-gnu-emacs@gnu.org; Fri, 30 Dec 2016 16:10:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cN4R8-0004e9-5L for bug-gnu-emacs@gnu.org; Fri, 30 Dec 2016 16:10:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45243) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cN4R8-0004e1-2f for bug-gnu-emacs@gnu.org; Fri, 30 Dec 2016 16:10:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cN4R7-0002IS-SH for bug-gnu-emacs@gnu.org; Fri, 30 Dec 2016 16:10: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: Fri, 30 Dec 2016 21:10: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.14831321478748 (code B ref 25265); Fri, 30 Dec 2016 21:10:01 +0000 Original-Received: (at 25265) by debbugs.gnu.org; 30 Dec 2016 21:09:07 +0000 Original-Received: from localhost ([127.0.0.1]:60642 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cN4QE-0002H2-PB for submit@debbugs.gnu.org; Fri, 30 Dec 2016 16:09:07 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:52650) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cN4QD-0002GY-27 for 25265@debbugs.gnu.org; Fri, 30 Dec 2016 16:09:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cN4Q3-0004RT-Pk for 25265@debbugs.gnu.org; Fri, 30 Dec 2016 16:08:59 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:60843) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cN4Q3-0004RP-M6; Fri, 30 Dec 2016 16:08:55 -0500 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:3366 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1cN4Q2-0005HN-Ua; Fri, 30 Dec 2016 16:08:55 -0500 In-reply-to: <20161230184532.GA3754@breton.holly.idiocy.org> (message from Alan Third on Fri, 30 Dec 2016 18:45:32 +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:127596 Archived-At: > Date: Fri, 30 Dec 2016 18:45:32 +0000 > From: Alan Third > Cc: charles@aurox.ch, 25265@debbugs.gnu.org > > > > If there’s NS input, it’s processed by the NSApp loop > > > > Processed how? Shouldn't Emacs be involved in this processing? IOW, > > these events should be read by Emacs, via the read_socket_hook. > > Ah! Is this the missing piece of the puzzle? When the [NSApp run] loop > receives an event, say keyboard input, it creates an emacs_event and > then raises SIGIO (via hold_event). SIGIO causes ns_read_socket to be > run, which ALSO tries to run [NSApp run]. > > 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. > I’ve just commented out the section of ns_read_socket that calls > [NSApp run] and I can’t see any difference in behaviour. I suspect > that someone’s doubled up on it when they didn’t need to. I cannot help you here. Maybe it's needed for Emacs to be more responsive? If you run "git log -L" on ns_read_socket, does the history tell anything about why this call was added? Perhaps some discussion or bug report? > > One possible solution might be to let only one thread, say the main > > thread, to call [NSApp run]. The other threads, when they get into > > ns_select, will behave as if Emacs runs in non-GUI mode, and will only > > call pselect. Not sure what this will mean from the POV of all > > threads being equal (since the delicate dance between ns_select and > > ns_read_socket is still unclear to me), but at least it might avoid > > crashes and hangs. Can you try something like that? > > Yes, I will. Am I right in thinking that if we remove all the NSApp > junk from ns_select it will literally just be calling pselect with > the same arguments? It looks like that, yes. > 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? > Thanks for helping with this, I don’t think I’d be able to work it out > on my own. Thank you for digging into the problem.