emacs-devel
[Top][All Lists]
Advanced

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

Re: save-excursion and multi-thread?


From: Eli Zaretskii
Subject: Re: save-excursion and multi-thread?
Date: Mon, 27 Sep 2021 07:36:05 +0300

> From: Qiantan Hong <qhong@mit.edu>
> CC: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
> Date: Sun, 26 Sep 2021 19:42:25 +0000
> 
> > You can always use save-excursion in the other thread, no?
> Doesn’t looks like it’s protected
> (progn
>   (make-thread
>    (lambda ()
>      (save-excursion
>        (sleep-for 5)
>        (print (point)))))
>   (make-thread
>    (lambda ()
>      (save-excursion
>        (sleep-for 3)
>        (goto-char (point-min))
>        (sleep-for 3)))))
> This prints 1 instead of the point before the first save-excursion enters.

The print should be outside of save-excursion, of course.

> Moreover, the other thread can be the main UI thread, 
> I don’t know how I can protect it (assuming that save-excursion does protect,
> although it actually doesn’t).

Moving point behind the back of the main thread is a bad idea, you
will expose the movement to the user when redisplay hits.

> >> Does that convince you?
> > 
> > Convince me to do what? redesign and reimplement Lisp threads in
> > Emacs with very different design goals?
> Not doing anything, let’s figure out what’s correct first.

I don't see anything that needs fixing here.  Once again, the basic
design was to allow other threads work on other buffers, which is why
each thread has its own current buffer.  This is how this stuff was
designed, so yes, we are talking about design goals.

> I also don’t think a redesign is necessary, we just need to
> restore point state during thread switching, but I haven’t look at detail yet.

In interactive use, moving point in a thread that doesn't perform
redisplay will surprise the user, and I don't see how you could avoid
that.  So I don't think this idea will fly.

Would you mind explaining in more detail what you want to accomplish?
Perhaps there are better ways of doing that that are already
supported, or could be supported with cleaner changes.  I'm not going
to agree to any changes that would make it easier for 2 threads to
work on the same buffer, that way lies madness: buffer changes use a
lot of global machinery behind the scenes.



reply via email to

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