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: Tue, 13 Jun 2017 21:46:43 +0100 Message-ID: <20170613204643.GA98084@breton.holly.idiocy.org> References: <20170502204935.GA79100@breton.holly.idiocy.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Nq2Wo0NMKNjxTN9z" Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1497386835 10193 195.159.176.226 (13 Jun 2017 20:47:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 13 Jun 2017 20:47:15 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) Cc: 25265@debbugs.gnu.org To: "Charles A. Roelli" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jun 13 22:47:10 2017 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 1dKsiS-0002E3-Nr for geb-bug-gnu-emacs@m.gmane.org; Tue, 13 Jun 2017 22:47:09 +0200 Original-Received: from localhost ([::1]:45188 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKsiX-00022Y-Vt for geb-bug-gnu-emacs@m.gmane.org; Tue, 13 Jun 2017 16:47:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKsiP-000213-EP for bug-gnu-emacs@gnu.org; Tue, 13 Jun 2017 16:47:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dKsiM-0002Iz-9l for bug-gnu-emacs@gnu.org; Tue, 13 Jun 2017 16:47:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43607) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dKsiM-0002Iv-3w for bug-gnu-emacs@gnu.org; Tue, 13 Jun 2017 16:47:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dKsiL-0008VR-Qq for bug-gnu-emacs@gnu.org; Tue, 13 Jun 2017 16:47:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 13 Jun 2017 20:47: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.149738681432679 (code B ref 25265); Tue, 13 Jun 2017 20:47:01 +0000 Original-Received: (at 25265) by debbugs.gnu.org; 13 Jun 2017 20:46:54 +0000 Original-Received: from localhost ([127.0.0.1]:46284 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dKsiE-0008V1-Ag for submit@debbugs.gnu.org; Tue, 13 Jun 2017 16:46:54 -0400 Original-Received: from mail-wr0-f182.google.com ([209.85.128.182]:33635) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dKsiB-0008Un-Lp for 25265@debbugs.gnu.org; Tue, 13 Jun 2017 16:46:52 -0400 Original-Received: by mail-wr0-f182.google.com with SMTP id v104so151177533wrb.0 for <25265@debbugs.gnu.org>; Tue, 13 Jun 2017 13:46:51 -0700 (PDT) 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=BFUGHeNOjJZKIsOvmSd9ynUdeymBENS/wMB/ZRIdquA=; b=C4uvwzdJe5o3xoSRZiX+NgUbTwMfHnl0ZzOa/gfbskki0bqicgPEgEdf3poDISYWHN /fGGTqiy9Y6r5xEqPVPIoXsR+y6aC9BRWbo0lsXiiyeprpMy4yoZDTF/e+9uzV22Funl XNdkz9HBnk8wl0GXAa8PmdG4dFGPVlqLcYnNsX4tBzNMMLoytl74hrWkQOpdCshY7ntY L7axJ+xG3pddgI4qXVRJxG3WEInEQeXL6RxnDvjrAN1sRwRhq1L0HFh3rRsvab5tdD2y M951fvWT3YWNIFGYSrUqCrl+UB1KTdBOKcs8oMxGhLX8lS0VADnheDtEnv7vAfGw1jjg krIA== 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=BFUGHeNOjJZKIsOvmSd9ynUdeymBENS/wMB/ZRIdquA=; b=W95gNE7maNhNOL3l4lzygvnh0uA2Wo5e4kThuxgqlG78+o9qF0os9UJP+ZGRW790Kv LwQ2Vxx6PEZVNDjvKsOXDUN/nENyuSz+Jqr9uP9udpYbL9SGnIyg3FlCOEjfd3mY0cl0 Po6/vlZibv1G/9Dmbw9m0W9uwiOjusLXLiK7zuzG+ianDNU+zxp/UN/nzV7tgY9uR48D /tJQZEgapU6FIXBRHXe3qEmKzz4lxbtm97SuI/Yaim0KxsIj0GNWoKPgj+VlBn0ZCTft gJIAJVTN6qvA1+mf8QF9lAS2vHA+p+0JWugAgD0eCqyJVCZjVQYFAla5qh04+LmItgf/ Q4ug== X-Gm-Message-State: AKS2vOxwThB+wSghWZziwnAA+o424sFgSniHxkDEPqcwMA8SHmrHvvl1 smNltsqF3EnSiGKkrEU= X-Received: by 10.28.230.153 with SMTP id e25mr11598548wmi.41.1497386805666; Tue, 13 Jun 2017 13:46:45 -0700 (PDT) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-58c7-5550-e6e7-d91f.holly.idiocy.org. [2001:8b0:3f8:8129:58c7:5550:e6e7:d91f]) by smtp.gmail.com with ESMTPSA id g3sm26931694wrd.11.2017.06.13.13.46.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Jun 2017 13:46:44 -0700 (PDT) Content-Disposition: inline In-Reply-To: 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:133565 Archived-At: --Nq2Wo0NMKNjxTN9z Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Mon, Jun 12, 2017 at 09:32:21PM +0200, Charles A. Roelli wrote: > The issue seems to be improved now (not sure what changed it). > > I tried this sample code, and it worked without a crash: > > (dotimes (i 100) > (make-thread (lambda () "string"))) > > Then I tried this code, and there's a crash every few runs (or > sometimes, an infinite loop that can't be exited without killing the > process). The crash normally happens when I supply input (via the > keyboard), and the loop seems to be happen randomly. > > (make-thread (lambda () > (dotimes (i 10) > (sit-for 1) > (goto-char (random (buffer-size)))))) I went back and noticed an approach Eli suggested that I had given up on, but understood this time round. I’ve attached a patch that seems to not crash. It introduces a warning or two, and test/src/thread-tests.el randomly fails up to two tests, but no crashes afaics. > I also noticed GDB's I/O buffer printing many of these warnings as > soon as the `make-thread' form was called: > > 2017-06-12 21:13:55.943 Emacs[10829:6683] *** __NSAutoreleaseNoPool(): > Object 0x10216bf50 of class NSBezierPath autoreleased with no pool in place > - just leaking > 2017-06-12 21:13:55.944 Emacs[10829:6683] *** __NSAutoreleaseNoPool(): > Object 0x101ec41b0 of class NSBezierPath autoreleased with no pool in place > - just leaking > 2017-06-12 21:13:56.443 Emacs[10829:6683] *** __NSAutoreleaseNoPool(): > Object 0x10216c0f0 of class NSBezierPath autoreleased with no pool in place > - just leaking > 2017-06-12 21:13:56.444 Emacs[10829:6683] *** __NSAutoreleaseNoPool(): > Object 0x101ec43e0 of class NSBezierPath autoreleased with no pool in place > - just leaking It must be a sub‐thread running some objective c code without an autorelease pool. It would be nice to be able to work out where that’s happening. Perhaps threads will need to define an autorelease pool on creation, and drain it on ending... -- Alan Third --Nq2Wo0NMKNjxTN9z Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-Fix-threads-on-NS-bug-25265.patch" >From 22c33d9f2516dd488c3d76ccb3360e4855df7bb6 Mon Sep 17 00:00:00 2001 From: Alan Third Date: Tue, 13 Jun 2017 21:40:25 +0100 Subject: [PATCH] Fix threads on NS (bug#25265) --- src/nsterm.h | 2 +- src/nsterm.m | 10 ++++++++-- src/process.c | 4 ++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/nsterm.h b/src/nsterm.h index bed0b92c79..10d5db2cff 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -1226,7 +1226,7 @@ extern void x_set_z_group (struct frame *f, Lisp_Object new_value, Lisp_Object old_value); extern int ns_select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timespec const *timeout, - sigset_t const *sigmask); + sigset_t *sigmask); extern unsigned long ns_get_rgb_color (struct frame *f, float r, float g, float b, float a); diff --git a/src/nsterm.m b/src/nsterm.m index e05dbf45fb..8fc27ed752 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -4294,7 +4294,7 @@ in certain situations (rapid incoming events). int ns_select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timespec const *timeout, - sigset_t const *sigmask) + sigset_t *sigmask) /* -------------------------------------------------------------------------- Replacement for select, checking for events -------------------------------------------------------------------------- */ @@ -4327,7 +4327,13 @@ in certain situations (rapid incoming events). if (NSApp == nil || ![NSThread isMainThread] || (timeout && timeout->tv_sec == 0 && timeout->tv_nsec == 0)) - return pselect (nfds, readfds, writefds, exceptfds, timeout, sigmask); + return thread_select(pselect, nfds, readfds, writefds, + exceptfds, timeout, sigmask); + else + { + struct timespec t = {0, 0}; + thread_select(pselect, 0, NULL, NULL, NULL, &t, sigmask); + } [outerpool release]; outerpool = [[NSAutoreleasePool alloc] init]; diff --git a/src/process.c b/src/process.c index 2a1c2eecde..eec907e14a 100644 --- a/src/process.c +++ b/src/process.c @@ -5371,6 +5371,10 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, nfds = xg_select (max_desc + 1, &Available, (check_write ? &Writeok : 0), NULL, &timeout, NULL); +#elif defined HAVE_NS + nfds = ns_select (max_desc + 1, + &Available, (check_write ? &Writeok : 0), + NULL, &timeout, NULL); #else /* !HAVE_GLIB */ nfds = thread_select ( # ifdef HAVE_NS -- 2.12.0 --Nq2Wo0NMKNjxTN9z--