[Top][All Lists]

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

Re: Questions about throw-on-input

From: Stefan Monnier
Subject: Re: Questions about throw-on-input
Date: Mon, 11 May 2020 14:24:21 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> That could be a game-changer, it would open up the path for making Elisp
> a lot more asynchronous than it is now. You could load up heavy work on
> a background thread, and (of course assuming it can be slit into smaller
> pieces) simply yield whenever input is detected. And when the main
> thread has done its part the worker would simply pick up again where it
> left off.

I think calling `thread-yield` frequently enough should(!) do the trick.
No need to call `input-pending-p`.

IOW if `thread-yield` doesn't do the trick, you should
likely `M-x report-emacs-bug`.

> I don't think this is possible right now, other than maybe with
> awkwardly pushing around timers and while-no-input, or using mandatory
> 1ms pauses instead of proper yielding as in my benchmark, which is
> probably not exactly ideal either.

Actually a better solution is often to run in a separate process
(e.g. via `async.el`).  That also lets you use the various CPU cores
lying idle ;-)

> And while we are on the topic of threads, I wonder what is the
> maintainers' opinion on https://nullprogram.com/blog/2018/05/31/,
> specifically this part:
>> Update: ThreadSanitizer (TSan) quickly shows that Emacs’ threading
>> implementation has many data races, making it completely
>> untrustworthy. Until this is fixed, nobody should use Emacs threads
>> for any purpose, and threads should disabled at compile time.

Sounds very credible, but I'll let someone else take care of this,
because it's too far from my area of expertise.


reply via email to

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