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: Sun, 18 Jun 2017 15:01:18 +0100 Message-ID: <20170618140118.GA33083@breton.holly.idiocy.org> References: <20170502204935.GA79100@breton.holly.idiocy.org> <20170613204643.GA98084@breton.holly.idiocy.org> <20170615190432.GA12317@breton.holly.idiocy.org> <20170616194531.GA27453@breton.holly.idiocy.org> <20170616205139.GA27574@breton.holly.idiocy.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="d6Gm4EdcadzBjdND" Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1497794538 1656 195.159.176.226 (18 Jun 2017 14:02:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 18 Jun 2017 14:02:18 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) Cc: Noam Postavsky , 25265@debbugs.gnu.org To: "Charles A. Roelli" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jun 18 16:02:12 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 1dMamJ-0008Ts-UW for geb-bug-gnu-emacs@m.gmane.org; Sun, 18 Jun 2017 16:02:12 +0200 Original-Received: from localhost ([::1]:38473 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMamN-0005D1-Ew for geb-bug-gnu-emacs@m.gmane.org; Sun, 18 Jun 2017 10:02:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50643) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMamF-0005Ck-1J for bug-gnu-emacs@gnu.org; Sun, 18 Jun 2017 10:02:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dMamB-0001xD-0h for bug-gnu-emacs@gnu.org; Sun, 18 Jun 2017 10:02:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:52540) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dMamA-0001we-Qq for bug-gnu-emacs@gnu.org; Sun, 18 Jun 2017 10:02:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dMamA-0003HS-GM for bug-gnu-emacs@gnu.org; Sun, 18 Jun 2017 10:02:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 18 Jun 2017 14:02: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.149779448912569 (code B ref 25265); Sun, 18 Jun 2017 14:02:02 +0000 Original-Received: (at 25265) by debbugs.gnu.org; 18 Jun 2017 14:01:29 +0000 Original-Received: from localhost ([127.0.0.1]:55216 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dMald-0003Ge-EC for submit@debbugs.gnu.org; Sun, 18 Jun 2017 10:01:29 -0400 Original-Received: from mail-wm0-f54.google.com ([74.125.82.54]:35066) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dMalb-0003GP-MB for 25265@debbugs.gnu.org; Sun, 18 Jun 2017 10:01:28 -0400 Original-Received: by mail-wm0-f54.google.com with SMTP id x70so59144272wme.0 for <25265@debbugs.gnu.org>; Sun, 18 Jun 2017 07:01:27 -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=feqk9UkHA/o7l+zhGSSYIIhInVV3KglzVt6feKp80AI=; b=HXLXQlL9PucYCogxmiDUKAlNqZ0zRMqoxxYV8WCqNmYujRKGCDyznXHVuBTAJV5Pjk v2E6Yfctmfeu/LykeqbuBmxBtYWUTEtD1AAbOLuhrBCE1pqzem84duCT0xQ7vADP5Y+B X51dQ7aVzNV3rvsW1jxF6UAAOL0H2VeUBLfkcfDUaF7B3UL+e4+K0sqanKtMHT/Gv+x7 05TgUHFxH/B3p53Fz+5ut+ZIUX3WoWieV9Fh+4LcrHZK8SG1SP2PAkScNJ183ddj9aha GAGW7U/Rk9OYP9IbRZRAIfLbDKVnURZdT2+ViWB8eMS0ANiKB56kIs8xlseKZVdLJeJS sZCg== 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=feqk9UkHA/o7l+zhGSSYIIhInVV3KglzVt6feKp80AI=; b=G30y6vd9eL2lTQektvyegAB4Yz+Rq4pEDJSyDcm4tKv5utZX1dLK2c6suIziwsJK4w IQe5ccIoSAZukX6/cDC1UFFhkZsIYunEak4oJYy4ofWjGc+tWS1PhnM3QgAxA1DBUFA6 vX86UxDMTTO6QeYtD0eOUD2XuZUEy/JO7N+tLBOyC/+l9ya+R79wxBjMKVZU9QSBe8Yz nhuS7v9JZPn161M8JIgOguwTi2AUj8gWhIZQyjoXC+BRP4JUjuiswpI4KEPps4XPtHXV 0uj3V1aa7nGW9b1rVMb/Ngg6Gwn5zwQh040gekMzsqni4HpVWI/IyBr7Rad3lTV1Vzz4 kpuA== X-Gm-Message-State: AKS2vOzOFZB6w1TpGSlN8ZtiruZ3jsmsM+pVhJ/14tLNXgTTT6opL/T0 321d8oUq9U4UhTtRQfOBWg== X-Received: by 10.28.51.199 with SMTP id z190mr3589927wmz.103.1497794481862; Sun, 18 Jun 2017 07:01:21 -0700 (PDT) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-9c48-3d60-5bc4-3b29.holly.idiocy.org. [2001:8b0:3f8:8129:9c48:3d60:5bc4:3b29]) by smtp.gmail.com with ESMTPSA id b192sm3925712wmf.25.2017.06.18.07.01.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Jun 2017 07:01:20 -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:133728 Archived-At: --d6Gm4EdcadzBjdND Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Sun, Jun 18, 2017 at 03:05:04PM +0200, Charles A. Roelli wrote: > The tests sometimes all pass with the updated patch, but then I got > this once (the errors you've seen previously, I think): > Yeah, they look the same. I’m not sure what I can do to fix them if they’re still happening. > I also tried this way of running the tests in batch mode: > > cd test && rm -rf src/thread-tests.log && make src/thread-tests.log > > but got a segfault: > > GEN src/thread-tests.log > /bin/sh: line 1: 87214 Segmentation fault HOME=/nonexistent > EMACSLOADPATH= LC_ALL=C > EMACS_TEST_DIRECTORY=/Volumes/Toblerone/Code/emacs-devel/test "../src/emacs" > -batch --no-site-file --no-site-lisp -L ":." -l ert -l src/thread-tests.el > --eval "(ert-run-tests-batch-and-exit nil)" > src/thread-tests.log 2>&1 > Running 28 tests (2017-06-18 15:00:03+0200) > make: *** [src/thread-tests.log] Error 139 > > I'm not sure where the problem is happening (or if it's specific to > NS). The file 'src/thread-tests.log' also doesn't give any extra > information (besides 'Running 28 tests (2017-06-18 15:00:03+0200)'). Yeah, I think that’s because I, accidentally, have the non‐GUI version trying to run some GUI stuff. I noticed this myself yesterday. Running NS Emacs without a GUI has always worked with threads because it just bypasses the NS run loop which is the problem. I’ve attached a new patch that actually checks whether we’re running the NS GUI. -- Alan Third --d6Gm4EdcadzBjdND Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-Fix-threads-on-NS-bug-25265.patch" >From 62ac72333084ae32719d63b82166f1c6daee1ed9 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 (ns_select): Compiler doesn't like sigmask being const. (ns_run_loop_break) [HAVE_PTHREAD]: New function. src/nsterm.m (ns_select): Call thread_select from within ns_select. (ns_run_loop_break) [HAVE_PTHREAD]: New function. (ns_send_appdefined): Don't wait for main thread when sending app defined event. src/process.c (wait_reading_process_output): Call thread_select from within ns_select. src/systhread.c (sys_cond_broadcast) [HAVE_NS]: Break ns_select out of its event loop using ns_run_loop_break. --- src/nsterm.h | 7 +++++-- src/nsterm.m | 26 ++++++++++++++++++++++---- src/process.c | 13 ++++++------- src/systhread.c | 11 +++++++++++ 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/nsterm.h b/src/nsterm.h index bed0b92c79..73d846d114 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -1225,8 +1225,11 @@ extern void x_set_no_accept_focus (struct frame *f, Lisp_Object new_value, 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); + fd_set *exceptfds, struct timespec *timeout, + sigset_t *sigmask); +#ifdef HAVE_PTHREAD +extern void ns_run_loop_break (void); +#endif 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..bf83550b3d 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -4068,7 +4068,7 @@ overwriting cursor (usually when cursor on a tab) */ app->nextappdefined = value; [app performSelectorOnMainThread:@selector (sendFromMainThread:) withObject:nil - waitUntilDone:YES]; + waitUntilDone:NO]; return; } @@ -4293,8 +4293,8 @@ 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) + fd_set *exceptfds, struct timespec *timeout, + 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]; @@ -4430,6 +4436,18 @@ in certain situations (rapid incoming events). return result; } +#ifdef HAVE_PTHREAD +void +ns_run_loop_break () +/* Break out of the NS run loop in ns_select or ns_read_socket. */ +{ + NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_run_loop_break"); + + /* If we don't have a GUI, don't send the event. */ + if (NSApp != NULL) + ns_send_appdefined(-1); +} +#endif /* ========================================================================== diff --git a/src/process.c b/src/process.c index 2a1c2eecde..abd017bb90 100644 --- a/src/process.c +++ b/src/process.c @@ -5371,14 +5371,13 @@ 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 + /* And NS builds call thread_select in ns_select. */ + nfds = ns_select (max_desc + 1, + &Available, (check_write ? &Writeok : 0), + NULL, &timeout, NULL); #else /* !HAVE_GLIB */ - nfds = thread_select ( -# ifdef HAVE_NS - ns_select -# else - pselect -# endif - , max_desc + 1, + nfds = thread_select (pselect, max_desc + 1, &Available, (check_write ? &Writeok : 0), NULL, &timeout, NULL); diff --git a/src/systhread.c b/src/systhread.c index a84060c18f..aee12a9b48 100644 --- a/src/systhread.c +++ b/src/systhread.c @@ -20,6 +20,10 @@ along with GNU Emacs. If not, see . */ #include #include "lisp.h" +#ifdef HAVE_NS +#include "nsterm.h" +#endif + #ifndef THREADS_ENABLED void @@ -130,6 +134,13 @@ void sys_cond_broadcast (sys_cond_t *cond) { pthread_cond_broadcast (cond); +#ifdef HAVE_NS + /* Send an app defined event to break out of the NS run loop. + It seems that if ns_select is running the NS run loop, this + broadcast has no effect until the loop is done, breaking a couple + of tests in thread-tests.el. */ + ns_run_loop_break (); +#endif } void -- 2.12.0 --d6Gm4EdcadzBjdND--