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

From: "Charles A. Roelli" <[email-masked]>
Date: Mon, 12 Jun 2017 21:32:21 +0200

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 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

On 02/05/2017 22:49, Alan Third wrote:
> On Sat, Dec 24, 2016 at 12:06:45PM +0100, Charles A. Roelli wrote:
>> Running Emacs -Q on the latest commit (e36a3882),
>>
>> M-: (make-thread (lambda () "string"))
>>
>> appears to hang Emacs immediately.
> I’ve been working on this on and off for a while now, and I just can’t
> fix it.
>
> I’ve attached two patches that together are the best I’ve managed to
> achieve, but unfortunately it randomly freezes up with 100% CPU usage.
>
> I’ve not yet managed to work out what it’s doing when it goes into the
> 100% CPU loop. I can only assume I’ve missed some crucial case in
> ns_select or something.
>
> The first patch stops the NS port from using SIGIO, as it seems to be
> the source of a number of problems. The second removes the NS event
> loop in ns_select as it requires block_input/unblock_input wrapped
> around it, but that’s what’s causing the crash in make-thread.
>
> Instead it just looks for whether there is a new NS event as I don’t
> think that requires blocking input.
>