From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: save-excursion and multi-thread? Date: Sun, 26 Sep 2021 22:02:17 +0300 Message-ID: <83wnn3ma86.fsf@gnu.org> References: <5713E898-28B8-456C-992C-F0332FACA9FF@mit.edu> <874ka7xjj5.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21885"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Tassilo Horn Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Sep 26 21:03:29 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mUZQv-0005ZK-68 for ged-emacs-devel@m.gmane-mx.org; Sun, 26 Sep 2021 21:03:29 +0200 Original-Received: from localhost ([::1]:58714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mUZQu-0005SV-5e for ged-emacs-devel@m.gmane-mx.org; Sun, 26 Sep 2021 15:03:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33222) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUZPn-00043B-E3 for emacs-devel@gnu.org; Sun, 26 Sep 2021 15:02:19 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:57192) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mUZPn-0003Hk-6K for emacs-devel@gnu.org; Sun, 26 Sep 2021 15:02:19 -0400 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4777 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUZPi-0001U9-CG; Sun, 26 Sep 2021 15:02:17 -0400 In-Reply-To: <874ka7xjj5.fsf@gnu.org> (message from Tassilo Horn on Sun, 26 Sep 2021 20:21:39 +0200) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:275529 Archived-At: > From: Tassilo Horn > Date: Sun, 26 Sep 2021 20:21:39 +0200 > > Qiantan Hong writes: > > > I tried > > (make-thread > > (lambda () > > (save-excursion (goto-char (point-min)) (sleep-for 1)))) > > In *scratch*. > > > > It seems that after the thread yields (because of sleep-for) it > > doesn’t restore point position, and after 1 second cursor is reseted > > to the original position, > > The `sleep-for' is part of the thread's function, and also contained in > the `save-excursion'. So how could it be different? > > > discarding any of my movements during this 1 second. > > > > Is this how save-excursion supposed to work? > > It’s inconsistent with the behavior of special variable + dynamic > > bindings, which works currently under multi-thread. > > How are those related? > > > What’s the supposed way to have “thread-local” movements? > > The thing is, right now there are threads in emacs but no actual > parallelism. There's ever only one thread active and emacs switches > between the existing threads at certain conditions, e.g., when one > thread waits for input or a condition variable. I guess another one > might be `sleep-for' which would obviously make a lot of sense. > > Oh, ok, I think now I got your question. If `point' was a special > variable, and let-bindings of special variables in a thread are local to > this thread, then you would naturally have thread-local movements. > > I think as long as your thread doesn't use `sit-for', `sleep-for', > or reads input, you can be sure it won't be interrupted. A thread can also be preempted by one of the following: . calls to thread primitives such as thread-yield . calls to primitives that read from processes, such as accept-process-output, and anything that calls these . becoming idle (which is a kind of "reading input", but maybe not everyone will realize that . waiting for X selections to do their thing