emacs-devel
[Top][All Lists]
Advanced

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

Re: Make computational threads leave user interface usable


From: John Wiegley
Subject: Re: Make computational threads leave user interface usable
Date: Wed, 01 Nov 2017 11:12:02 -0700
User-agent: Gnus/5.130016 (Ma Gnus v0.16) Emacs/26.0 (darwin)

>>>>> "PP" == Paul Pogonyshev <address@hidden> writes:

PP> Since several versions Emacs has Lisp threads, but they are not used much,
PP> because 1) only one thread executes at any given time; 2) threads yield
PP> control to each other only with explicit (thread-yield) call or IO blocks.
PP> Which means that it is pointless to start a new thread for heavy
PP> computation: it will lock UI until finished anyway.

I wouldn't say it's pointless, just that it calls for a programming regimen
where you add (thread-yield) calls at appropriate places.

PP> Attached patch tries to solve point 2 only by making threads
PP> automatically yield control to each other from time to time. The patch
PP> is mainly for discussion.

This would introduce the sort of indeterminacy that raised so much objection
to threading support last year. I'm fairly opposed to pre-emptive threading
until we've heard from the field about the success of green threading.

    (make-thread (lambda ()
                   (dotimes (n 10000000)
                     (when (= (% n 1000000) 0)
                       (message "%s" n)))
                   (message "done")))

I think the problem here is not with Emacs' threading model, but how you've
written the code. It is currently a _feature_ that control is not taken away
while engaged in such a computation. For example, this allows delicate state
manipulation without interference from other threads.

If periodic suspension were desired, you could have written:

    (make-thread (lambda ()
                   (dotimes (n 10000000)
                     (thread-yield)
                     (when (= (% n 1000000) 0)
                       (message "%s" n)))
                   (message "done")))

This gives the UI access to Emacs again, but otherwise keeps executing if no
other threads need control.

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2



reply via email to

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