all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Spencer Baugh <sbaugh@janestreet.com>
Cc: emacs-devel@gnu.org
Subject: Re: Releasing the thread global_lock from the module API
Date: Fri, 01 Mar 2024 20:44:35 +0200	[thread overview]
Message-ID: <86a5nhrdv0.fsf@gnu.org> (raw)
In-Reply-To: <ierbk7xua8j.fsf@janestreet.com> (message from Spencer Baugh on Fri, 01 Mar 2024 12:34:36 -0500)

> From: Spencer Baugh <sbaugh@janestreet.com>
> Date: Fri, 01 Mar 2024 12:34:36 -0500
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > It isn't clear what exactly do you want added, since calls to
> > thread-yield and similar APIs (like sleep-for and
> > accept-process-output), which release and re-acquire the global lock,
> > are already possible from Lisp threads.  What exactly is missing?
> 
> Those release and re-acquire the global lock, yes, but they don't allow
> module code to run on the thread while the global lock is released.

That's because the Emacs Lisp thread machinery cannot allow that.  A
Lisp thread has full access to the Emacs global state, so we cannot
allow more than one thread to have that at the same time.

> We can't do:
> - Lisp thread A calls module_work
> - On thread A, module_work releases the global lock.
> - On thread A, module_work starts native threads X and Y,

You can do that if the native threads are started before releasing the
global lock.

>   and does Emacs-independent work across all of these threads in parallel.

What do you mean by "Emacs-independent work across all of these
threads in parallel"?  If you want to break out of the restriction of
having only one Lisp thread running at any given time, then this is
IMO impossible without redesigning and reimplementing the current
threads machinery.

> Releasing the global lock allows Lisp thread B to run while Lisp thread
> A is running the module.

As explained above, you can do that already.

> > I think this is already possible, see above.  I guess I'm missing
> > something.
> 
> I don't think it is.  How would a module release global_lock, call a C
> library function on the current thread, and then re-acquire the global
> lock?  Can you say how you would do that with the APIs we have today?

If a thread releases a global lock, it cannot run the Lisp machine
until it re-acquire the global lock.  So what you want is impossible
within the current threads framework, unless you start native
(non-Lisp) threads which cannot safely access the Emacs global state.



  reply	other threads:[~2024-03-01 18:44 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-01 14:53 Releasing the thread global_lock from the module API Spencer Baugh
2024-03-01 16:47 ` Eli Zaretskii
2024-03-01 17:34   ` Spencer Baugh
2024-03-01 18:44     ` Eli Zaretskii [this message]
2024-03-01 19:02       ` Spencer Baugh
2024-03-01 19:26         ` Eli Zaretskii
2024-03-01 19:51           ` Spencer Baugh
2024-03-01 20:42             ` Eli Zaretskii
2024-03-01 21:21               ` Spencer Baugh
2024-03-01 21:34                 ` Eli Zaretskii
2024-03-01 21:56                   ` Spencer Baugh
2024-03-02  6:43                     ` Eli Zaretskii
2024-03-02 16:39                       ` sbaugh
2024-03-02 17:02                         ` Eli Zaretskii
2024-03-02 20:33                           ` Spencer Baugh
2024-03-03  6:13                             ` Eli Zaretskii
2024-03-03 13:19                               ` sbaugh
2024-03-03 15:42                                 ` Dmitry Gutov
2024-03-03 15:51                                 ` Eli Zaretskii
2024-03-01 19:30     ` tomas
2024-03-01 23:53       ` Dmitry Gutov
2024-03-02  5:57         ` tomas
2024-03-02 15:35           ` Dmitry Gutov
2024-03-02 16:31             ` tomas
2024-03-02 21:41               ` sbaugh
2024-03-03  6:25                 ` tomas

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=86a5nhrdv0.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=sbaugh@janestreet.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.