From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#25265: make-thread crashes in OS X 10.6 Date: Fri, 30 Dec 2016 18:45:32 +0000 Message-ID: <20161230184532.GA3754@breton.holly.idiocy.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> 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 1483123582 25286 195.159.176.226 (30 Dec 2016 18:46:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 30 Dec 2016 18:46:22 +0000 (UTC) User-Agent: Mutt/1.7.1 (2016-10-04) Cc: charles@aurox.ch, 25265@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Dec 30 19:46:14 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 1cN2Br-0004g0-Fr for geb-bug-gnu-emacs@m.gmane.org; Fri, 30 Dec 2016 19:46:07 +0100 Original-Received: from localhost ([::1]:41147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cN2Bw-0001cU-4y for geb-bug-gnu-emacs@m.gmane.org; Fri, 30 Dec 2016 13:46:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cN2Bq-0001cO-3b for bug-gnu-emacs@gnu.org; Fri, 30 Dec 2016 13:46:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cN2Bm-0005Zn-Sh for bug-gnu-emacs@gnu.org; Fri, 30 Dec 2016 13:46:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45201) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cN2Bm-0005ZZ-PS for bug-gnu-emacs@gnu.org; Fri, 30 Dec 2016 13:46:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cN2Bm-0007MS-Gm for bug-gnu-emacs@gnu.org; Fri, 30 Dec 2016 13:46:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 30 Dec 2016 18:46:02 +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.148312353928263 (code B ref 25265); Fri, 30 Dec 2016 18:46:02 +0000 Original-Received: (at 25265) by debbugs.gnu.org; 30 Dec 2016 18:45:39 +0000 Original-Received: from localhost ([127.0.0.1]:60600 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cN2BP-0007Ln-43 for submit@debbugs.gnu.org; Fri, 30 Dec 2016 13:45:39 -0500 Original-Received: from mail-wj0-f174.google.com ([209.85.210.174]:35042) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cN2BN-0007Lb-R1 for 25265@debbugs.gnu.org; Fri, 30 Dec 2016 13:45:38 -0500 Original-Received: by mail-wj0-f174.google.com with SMTP id v7so383753895wjy.2 for <25265@debbugs.gnu.org>; Fri, 30 Dec 2016 10:45:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=38lEhmpaW76fQSaNtjtAqb9/aKmBpiPowxE7FAB+Ufw=; b=UxvRUyxmD2M1jKOoRick9AaGT1nZ4wVr2ym0aAtiYxPQh48JwhBw3WWoEIZeNsH8Pq p/w4yoUFYqm79jbRLePMbLA/xs6Obz/uJh7oy0hFGymU2MdWbfAoMlHWPahQRf9dw8DC LGg/KptMjeI6nYcWb00IlMwBPfFo9J0U+wp08xfyX9Bq6gRTQ2KPu3++yvYQtlp1BoOm vlgzAJfGWzFv7NalCrS/IomvV0VPUbSpT8wm33OkwU/UfVJlhhLJ37V0WDez5sbfXyin Ds/gl3itU9BWIZUHA8BB18GWszwRhyniuGtMcMuz56hMKfpKHqnmLEyJFtgOOldi+sFC mljw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=38lEhmpaW76fQSaNtjtAqb9/aKmBpiPowxE7FAB+Ufw=; b=nRs1j9ASBGZa0iMomOv/edXpwW6z4UAnFaxMndMsR2+6F0b96vAgNe5eEcs9ze0CBs q4mnwXHtahFpQSC3iQTpBF0Kp4llkU67ND5MDYIvPZidfbsH+GUAfHTvvbEj/ZWdTyYu aqbfBdCibPbxZQisyHaCwaPFDy9nh8X8Xmz6ctmlDdqJF68Rx/2KuDFdwdgK6WaFjk9Q yHcU+pESq2ndv7AeHle5+O47qrbaS1MnCQwrQCn8SF/+vueAtPwg+QdWOOaLAtO8Y5Gv FHDuqaRAAVG1SgIFLvQB+4gd+yWLZbtMOuG9betndRngyUWpfQZRSGoF4nFgWcRPwov4 MpnA== X-Gm-Message-State: AIkVDXJzCQrK8Ro3Xt3yxaPOdIi5rL9tXdMwpjiPb5tKaGFs6Wl7ifj471/5nYuB36qgAw== X-Received: by 10.194.151.132 with SMTP id uq4mr38494773wjb.229.1483123532004; Fri, 30 Dec 2016 10:45:32 -0800 (PST) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-fcf8-7042-dd5f-6680.holly.idiocy.org. [2001:8b0:3f8:8129:fcf8:7042:dd5f:6680]) by smtp.gmail.com with ESMTPSA id e6sm74857461wjw.33.2016.12.30.10.45.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Dec 2016 10:45:31 -0800 (PST) Content-Disposition: inline In-Reply-To: <83vau2u0a1.fsf@gnu.org> 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:127588 Archived-At: On Thu, Dec 29, 2016 at 07:12:54PM +0200, Eli Zaretskii wrote: > > Date: Wed, 28 Dec 2016 19:36:33 +0000 > > From: Alan Third > > Cc: charles@aurox.ch, 25265@debbugs.gnu.org > > > > I’m slowly beginning to understand what’s going on in ns_select. It > > seems the idea is that it should detect both input on file descriptors > > (using pselect in the background), and NS events coming from [NSApp > > run]. > > What do "NS events" include? Do they include, for example, keyboard > input? As far as I can tell it’s mouse and keyboard input, as well as messages from the ‘window manager’, telling it to close the frame, etc. > > There is another thread that runs in a loop (fd_handler), and when > > it’s signalled from ns_select, it runs pselect. At the same time > > ns_select sets up a timer, then it calls [NSApp run]. > > (I think ns_select only sets up a timer when there are no descriptors > to watch, to avoid waking up the fd_handler thread in that case.) > > So this means there are 2 jobs to be done here: the pselect call and > the [NSApp run] call. Correct on both counts. > > 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’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. > 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? 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?) Replace ns_select with pselect. Thanks for helping with this, I don’t think I’d be able to work it out on my own. -- Alan Third