* Re: master 4ac4cec652f: Prevent freezes on macOS (bug#69561)
[not found] ` <20240313061054.71155C1FB4A@vcs2.savannah.gnu.org>
@ 2024-03-13 7:45 ` Po Lu
2024-03-13 8:48 ` Gerd Möllmann
0 siblings, 1 reply; 4+ messages in thread
From: Po Lu @ 2024-03-13 7:45 UTC (permalink / raw)
To: emacs-devel; +Cc: Gerd Möllmann
Gerd Moellmann <gerd@gnu.org> writes:
> if (NSApp == nil
> || ![NSThread isMainThread]
> || (timeout && timeout->tv_sec == 0 && timeout->tv_nsec == 0))
> - return thread_select (pselect, nfds, readfds, writefds,
> - exceptfds, timeout, sigmask);
> + thread_select (pselect, nfds, readfds, writefds,
> + exceptfds, timeout, sigmask);
Far be it from me to offer advice on code I know very little about, but
on the surface this appears to force non-main threads to enter [NSApp
run] whenever they enter select. Is this really the desired behavior?
I should think that this function, being provided by the toolkit for the
purpose of running its event loop, must be called by strictly one thread
at a time.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: master 4ac4cec652f: Prevent freezes on macOS (bug#69561)
2024-03-13 7:45 ` master 4ac4cec652f: Prevent freezes on macOS (bug#69561) Po Lu
@ 2024-03-13 8:48 ` Gerd Möllmann
2024-03-13 11:07 ` Po Lu
0 siblings, 1 reply; 4+ messages in thread
From: Gerd Möllmann @ 2024-03-13 8:48 UTC (permalink / raw)
To: Po Lu; +Cc: emacs-devel, Gerd Möllmann
Po Lu <luangruo@yahoo.com> writes:
> Gerd Moellmann <gerd@gnu.org> writes:
>
>> if (NSApp == nil
>> || ![NSThread isMainThread]
>> || (timeout && timeout->tv_sec == 0 && timeout->tv_nsec == 0))
>> - return thread_select (pselect, nfds, readfds, writefds,
>> - exceptfds, timeout, sigmask);
>> + thread_select (pselect, nfds, readfds, writefds,
>> + exceptfds, timeout, sigmask);
>
> Far be it from me to offer advice on code I know very little about, but
> on the surface this appears to force non-main threads to enter [NSApp
> run] whenever they enter select. Is this really the desired behavior?
>
> I should think that this function, being provided by the toolkit for the
> purpose of running its event loop, must be called by strictly one thread
> at a time.
Well, let me first make the usual disclaimer that I don't know much
about about Cocoa. (And don't really want to, I must admit ;-)).
I couldn't find much advice which I'd call definite on using Cocoa from
multiple threads, except
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html#:~:text=Guidelines%20for%20using%20Cocoa%20from,are%20generally%20not%20thread%2Dsafe.
I interpret this as meaning that it's possible to do this, considering
that Emacs' threads run one at a time only, AFAIU. If that's no longer
the case, we have a problem, I agree.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: master 4ac4cec652f: Prevent freezes on macOS (bug#69561)
2024-03-13 8:48 ` Gerd Möllmann
@ 2024-03-13 11:07 ` Po Lu
2024-03-13 11:59 ` Gerd Möllmann
0 siblings, 1 reply; 4+ messages in thread
From: Po Lu @ 2024-03-13 11:07 UTC (permalink / raw)
To: Gerd Möllmann; +Cc: emacs-devel, Gerd Möllmann
Gerd Möllmann <gerd.moellmann@gmail.com> writes:
> I interpret this as meaning that it's possible to do this, considering
> that Emacs' threads run one at a time only, AFAIU. If that's no
> longer the case, we have a problem, I agree.
My mistake. I assumed thread_select was the function calling ns_select,
not the other way around. Nevertheless, we've received reports of the
toolkit aborting when invoked from a non-main thread, so would you
please test this change in an environment where several threads are
active?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: master 4ac4cec652f: Prevent freezes on macOS (bug#69561)
2024-03-13 11:07 ` Po Lu
@ 2024-03-13 11:59 ` Gerd Möllmann
0 siblings, 0 replies; 4+ messages in thread
From: Gerd Möllmann @ 2024-03-13 11:59 UTC (permalink / raw)
To: Po Lu; +Cc: emacs-devel, Gerd Möllmann
Po Lu <luangruo@yahoo.com> writes:
> Gerd Möllmann <gerd.moellmann@gmail.com> writes:
>
>> I interpret this as meaning that it's possible to do this, considering
>> that Emacs' threads run one at a time only, AFAIU. If that's no
>> longer the case, we have a problem, I agree.
>
> My mistake. I assumed thread_select was the function calling ns_select,
> not the other way around. Nevertheless, we've received reports of the
> toolkit aborting when invoked from a non-main thread, so would you
> please test this change in an environment where several threads are
> active?
I'll put that on my todo list, but it can take me some time.
I think the change is necessary if or if not what you describe can
happen, because without it Emacs freezes for me somewhere between 0s and
a few hours after starting it. With the fix, it didn't freeze at all.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-03-13 11:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <171031025289.32157.8913441761015064536@vcs2.savannah.gnu.org>
[not found] ` <20240313061054.71155C1FB4A@vcs2.savannah.gnu.org>
2024-03-13 7:45 ` master 4ac4cec652f: Prevent freezes on macOS (bug#69561) Po Lu
2024-03-13 8:48 ` Gerd Möllmann
2024-03-13 11:07 ` Po Lu
2024-03-13 11:59 ` Gerd Möllmann
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).