Subject: bug#75275: 30.0.92; `make-thread` bug on macOS 15.2

From: Stefan Kangas <[email-masked]>
Date: Thu, 2 Jan 2025 08:35:14 -0600

Gerd Möllmann <[email-masked]> writes:

> I have something in my notes which might or might not help:
>
>   * Breakpoint for errors displayed by macOS on stderr
>
>   Set a breakpoint on CGPostError to find sources of errors.
>
>   #+begin_src sh
>   To find out from where macOS prints stuff to stderr, like
>   023-07-20 13:41:17.073449+0200 emacs[53072:1205906] [default]
>       CGSWindowShmemCreateWithPort failed on port 0
>   b _os_log_error_impl
>   b _os_log_impl
>   b _os_log_debug_impl
>   b _os_log_fault_impl
>   #+end_src
>
> If on of these breakpoints is hit when the error is displayed, we could
> perhaps see why ns_select_1 calls EmacsApp.run. In my understanding, it
> shouldn't because Cocoa event handling should only be done in the main
> thread.
>
> If the breakpoints are not hit, we could instrument ns_select_1 to call
> an empty function do_break on which we could set a breakpoint.
>
>   if (![NSThread isMainThread])
>     do_break ();
>   [NSApp run];
>
> Or something like that. The question would be what in the code above the
> [NSApp run] is wrong so that we land here. Probably some if condition.
>
> CC to Alan Third.

Thanks, I didn't have time to look into the above yet, but I noticed
that the bug wasn't there on emacs-29 and bisected the issue:

4ac4cec652ffaca4333d8f297b8a6c0e5bd79c68 is the first bad commit
commit 4ac4cec652ffaca4333d8f297b8a6c0e5bd79c68
Author: Gerd Möllmann <[email-masked]>
Date:   Sat Mar 9 15:06:29 2024 +0100

    Prevent freezes on macOS (bug#69561)

    * src/nsterm.m (ns_select_1): Store pending input_events. Always call
    [NSApp run].

 src/nsterm.m | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)