unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* NS port thread problems
       [not found]   ` <87k0i8cs59.fsf@yahoo.com>
@ 2021-10-20 20:43     ` Alan Third
  2021-10-21  0:35       ` Po Lu
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Third @ 2021-10-20 20:43 UTC (permalink / raw)
  To: Po Lu; +Cc: Emacs-Devel devel

On Wed, Oct 20, 2021 at 11:05:38AM +0800, Po Lu wrote:
> Alan Third <alan@idiocy.org> writes:
> 
> > I don’t think there’s really any way round this other than the massive
> > rewrite the NS port needs to make it handle threads correctly.
> 
> I don't understand the precise problem here (nor do I understand the
> thread code.)  Could you elaborate on what the problem is, and why it
> requires a massive rewrite?  Thanks.

macOS since, I think, 10.14 has required *ALL* GUI work to happen on
the main thread. This is a problem since, if you imagine running:

  (frame-set-width nil 100)

in a thread it will ultimately end up calling ns_set_window_size which
in turn will call "[window setFrame:frameRect display:NO]", which has
to be run in the main thread. ns_set_window_size also calls a number
of other GUI related methods, all of which need to run in the main
thread.

One solution would be to use Objective C "blocks" to run the code in
the main thread, but GCC doesn't support them, so that's out.

Another option is to use a "proxy" to send the messages to the main
thread. I know this works as I've written a proof of concept.

The main problem with that is that most of the functions we have that
will have to send method calls to the main thread have MANY method
calls, so that's a lot of back and forth to and from the main thread.
It seems to me that the better option is to try and simplify the code
so that ObjC classes provide the methods that the Emacsy C code
requires, rather than mixing it all together.

Additionally, I think even calling [NSView window] causes an error, so
any piece of code, that may run outside of the NS run loop, that
accesses an NSWindow MUST be sent to the main thread.

That's quite a lot of the C code in nsterm.

My ultimate plan, which I'm working towards very slowly, is to
introduce an EmacsFrame class that controls the EmacsViews and
EmacsWindows, and provides an API that matches roughly what the Emacs
side expects a frame to do. That's what most of my recent clean-up
work has been working towards.

I do not think that GNUstep has these limitations, so threads may not
be as prone to crash Emacs using it.
-- 
Alan Third



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: NS port thread problems
  2021-10-20 20:43     ` NS port thread problems Alan Third
@ 2021-10-21  0:35       ` Po Lu
  2021-10-23 10:27         ` Alan Third
  0 siblings, 1 reply; 3+ messages in thread
From: Po Lu @ 2021-10-21  0:35 UTC (permalink / raw)
  To: Alan Third; +Cc: Emacs-Devel devel

Alan Third <alan@idiocy.org> writes:

> On Wed, Oct 20, 2021 at 11:05:38AM +0800, Po Lu wrote:

> macOS since, I think, 10.14 has required *ALL* GUI work to happen on
> the main thread. This is a problem since, if you imagine running:
>
>   (frame-set-width nil 100)

> in a thread it will ultimately end up calling ns_set_window_size which
> in turn will call "[window setFrame:frameRect display:NO]", which has
> to be run in the main thread. ns_set_window_size also calls a number
> of other GUI related methods, all of which need to run in the main
> thread.

> One solution would be to use Objective C "blocks" to run the code in
> the main thread, but GCC doesn't support them, so that's out.

I'm aware of this feature, but I don't understand how it will allow for
running code in the main thread.

> I do not think that GNUstep has these limitations, so threads may not
> be as prone to crash Emacs using it.

Interesting, thanks.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: NS port thread problems
  2021-10-21  0:35       ` Po Lu
@ 2021-10-23 10:27         ` Alan Third
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Third @ 2021-10-23 10:27 UTC (permalink / raw)
  To: Po Lu; +Cc: Emacs-Devel devel

On Thu, Oct 21, 2021 at 08:35:01AM +0800, Po Lu wrote:
> Alan Third <alan@idiocy.org> writes:
> 
> > One solution would be to use Objective C "blocks" to run the code in
> > the main thread, but GCC doesn't support them, so that's out.
> 
> I'm aware of this feature, but I don't understand how it will allow for
> running code in the main thread.

You can send a block off to run in another thread. Look up
dispatch_sync and friends.

-- 
Alan Third



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-23 10:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <f6ac77bf-ef13-c30b-07ac-26712428e652@cvj.se>
     [not found] ` <20200129204234.GB60190@breton.holly.idiocy.org>
     [not found]   ` <87k0i8cs59.fsf@yahoo.com>
2021-10-20 20:43     ` NS port thread problems Alan Third
2021-10-21  0:35       ` Po Lu
2021-10-23 10:27         ` Alan Third

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