help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is automatic yield support feasible for threads?


From: Philipp
Subject: Re: Is automatic yield support feasible for threads?
Date: Tue, 9 Nov 2021 15:53:32 +0100


> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]