all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Third <alan@idiocy.org>
To: Po Lu <luangruo@yahoo.com>
Cc: Emacs-Devel devel <emacs-devel@gnu.org>
Subject: NS port thread problems
Date: Wed, 20 Oct 2021 21:43:41 +0100	[thread overview]
Message-ID: <YXB/fSoG1vvOGLe9@idiocy.org> (raw)
In-Reply-To: <87k0i8cs59.fsf@yahoo.com>

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



  reply	other threads:[~2021-10-20 20:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-29 11:27 bug#39343: 27.0.50; Thrad signal crashes Emacs with sgmentation fault Christian Johansson
2020-01-29 20:42 ` Alan Third
2020-01-29 21:05   ` Christian Johansson
2021-10-20  3:05   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-10-20 20:43     ` Alan Third [this message]
2021-10-21  0:35       ` NS port thread problems Po Lu
2021-10-23 10:27         ` Alan Third

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YXB/fSoG1vvOGLe9@idiocy.org \
    --to=alan@idiocy.org \
    --cc=emacs-devel@gnu.org \
    --cc=luangruo@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.