Subject: bug#25265: make-thread crashes in OS X 10.6

From: "Charles A. Roelli" <[email-masked]>
Date: Sun, 18 Jun 2017 15:05:04 +0200

The tests sometimes all pass with the updated patch, but then I got
this once (the errors you've seen previously, I think):

Selector: t
Passed:  26
Failed:  2 (2 unexpected)
Skipped: 0
Total:   28/28

Started at:   2017-06-18 14:54:43+0200
Finished.
Finished at:  2017-06-18 14:54:47+0200

.F........F.................

F thread-signal-early
     Test signaling a thread as soon as it is started by the OS.
     (ert-test-failed
      ((should-not
        (thread-alive-p thread))
       :form
       (thread-alive-p #<thread 0x102da5498>)
       :value t))

F threads-condvar-wait
     test waiting on conditional variable
     (ert-test-failed
      ((should
        (=
     (length
      (all-threads))
     1))
       :form
       (= 2 1)
       :value nil))

from nextstep/Emacs.app/Contents/MacOS/Emacs -Q -l ert -l 
test/src/thread-tests.el

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)').

On 16/06/2017 22:51, Alan Third wrote:
> On Fri, Jun 16, 2017 at 04:05:58PM -0400, Noam Postavsky wrote:
>> On Fri, Jun 16, 2017 at 3:45 PM, Alan Third <[email-masked]> wrote:
>>> The first one looks like the thread’s starting too quick?
>> I think it's rather failing to be killed by the `thread-signal' call.
> Ah, yes. I completely misread the test.
>
>>> The second looks like the thread’s not dying quick enough?
>> Same for that one. I don't know much about the thread internals, and
>> even less macOS internals though...
> Well, I’ve discovered that if I keep the mouse moving over the Emacs
> frame while the tests are running then none of them fail, so I think
> it’s something to do with ns_select jamming everything up for the
> duration of its timeout.
>
> I could probably get round that by getting the thread to fire off an
> NS app defined event when it dies. That would break ns_select out of
> its event loop, presumably letting the dying thread actually die...
>
> Amazingly that seems to have worked! Updated patch attached.