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: Qiantan Hong
Subject: Re: save-excursion and multi-thread?
Date: Sun, 26 Sep 2021 19:42:25 +0000


> On Sep 26, 2021, at 12:29 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Qiantan Hong <qhong@mit.edu>
>> CC: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
>> Date: Sun, 26 Sep 2021 19:21:38 +0000
>> 
>>>> I see. Can I fake that with indirect-buffer?
>>> 
>>> For moving point, I think you can.  But if you change the text, you
>>> will see the changes in the other threads as well.
>> That’s intended. 
>> I simply want point to behave like a proper global variable
> 
> But point is not a variable.  It's a property of a buffer, and all you
> have is a (read-only) accessor to that property.
> 
>> and save-excursion to behave like a proper let-binding.
> 
> 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.

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).

>> 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.
Whether to do the correct thing comes after that.
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.

reply via email to

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