all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Philipp <p.stephani2@gmail.com>
To: ndame <laszlomail@protonmail.com>
Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Re: Is automatic yield support feasible for threads?
Date: Tue, 9 Nov 2021 15:53:32 +0100	[thread overview]
Message-ID: <46501A5F-9C72-4048-8EEA-CE219D54CEC2@gmail.com> (raw)
In-Reply-To: <AVNN0Fy5Nl_7QuayhKKu5ANdTl0LfeVRUrI2mbxCRQFy4uMYogo0xEGiVK0-33H-jFh8HnyWCFbygrbUPS0PU7dCxh4tAstItkTfs871Zyg=@protonmail.com>



> Am 04.11.2021 um 18:10 schrieb ndame via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>:
> 
> AFAIK Emacs has cooperative threading, so a badly behaving thread can prevent UI updates, therefore if some costly operation is moved into a separate thread then the code has to be modified in order to yield periodically if the code doesn't do I/O.
> 
> If that's the case then what if the interpreter itself could support automatic yielding when some flag is set, so it could yield automatically after every several instructions?
> 
> For example, make-thread could have an optional argument specifying after how many instructions a thread-yield should be called automatically and if this argument is set then a global flag is set, so the interpreter knowns it should call yield regularly.
> 
> This automatic yielding would have some cost, but in return any code could safely be moved into a separate thread without the danger of locking up the UI if this optional argument is given to make-thread. So it could makes using cooperative threads easier.
> 
> Could such an automatic yield support be feasible for threads?

I don't think it's feasible.  Emacs Lisp code typically relies heavily on mutating global state (think buffer contents, the buffer list, `point', dynamic variables, ...), and normally doesn't put such state mutations into properly synchronized critical sections.  Yielding from such unprotected critical sections would result in very subtle bugs (`point' randomly moving around, corruption of internal data structures, buffers vanishing surprisingly, ...).


  reply	other threads:[~2021-11-09 14:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-04 17:10 Is automatic yield support feasible for threads? ndame via Users list for the GNU Emacs text editor
2021-11-09 14:53 ` Philipp [this message]
2021-11-10  7:46   ` ndame
2021-11-10 13:46     ` Eli Zaretskii
2021-11-11 18:11     ` Philipp

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=46501A5F-9C72-4048-8EEA-CE219D54CEC2@gmail.com \
    --to=p.stephani2@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=laszlomail@protonmail.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.