unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: luangruo@yahoo.com, emacs-devel@gnu.org
Subject: Re: Concurrency via isolated process/thread
Date: Sat, 08 Jul 2023 17:43:06 +0300	[thread overview]
Message-ID: <838rbqcvlx.fsf@gnu.org> (raw)
In-Reply-To: <87a5w6aa89.fsf@localhost> (message from Ihor Radchenko on Sat, 08 Jul 2023 11:55:34 +0000)

> From: Ihor Radchenko <yantar92@posteo.net>
> Cc: luangruo@yahoo.com, emacs-devel@gnu.org
> Date: Sat, 08 Jul 2023 11:55:34 +0000
> 
> >> And I still fail to see where base-buffer is _changed_. Is base buffer
> >> ever supposed to be changed?
> >
> > Another thread might change it while this thread examines it.
> 
> I was able to identify a single place in C code where buffer's base
> buffer is being set: in make-indirect-buffer, when the buffer is just
> created. So, it is safe to assume that buffer->base_buffer remain
> constant for any given live buffer. Unless I miss something.

C code can change.  It is not carved in stone.  Are we going to treat
the current state of the code as if it can never change?  That's
unwise.

> > Undo records changes in text properties and markers, and those are
> > different in the indirect buffers from the base buffers.  Does this
> > explain why we cannot simply point to the base buffer?
> 
> Are you sure? Text properties are certainly shared between indirect buffers.

That's not what the documentation says.

> >> > The C code accesses some buffer-local variables via Vfoo_bar C
> >> > variables.  Those need to be updated when the current buffer changes.
> >> 
> >> Now, when you explained this, it is also a big problem. Such C variables
> >> are a global state that needs to be kept up to date. Async will break
> >> the existing logic of these updates.
> >
> > Exactly.
> 
> I now looked a bit further, and what you are talking about are the
> variables defined via DEFVAR_PER_BUFFER.

Non necessarily.  Example: show-trailing-whitespace.

> If my understanding is correct, it should be safe to convert them into
> thread-local variables and update them within current thread when
> current_buffer (already thread-local) is altered.

It is only safe if no other thread will access the same buffer.  For
example, redisplay will be unable to show that buffer if it is visible
in some window, because its notion of the buffer-local values might be
inaccurate.

> >> > Oh, yes, they will: see fetch_buffer_markers, called by
> >> > set_buffer_internal_2.
> >> 
> >> Do you mean that in the existing cooperative Elisp threads, if one
> >> thread moves the point and yields to other thread, the other thread will
> >> be left with point in the same position (arbitrary, from the point of
> >> view of this other thread)?
> >
> > That's one problem, yes.  There are others.  Emacs Lisp uses point,
> > both explicitly and implicitly, all over the board.  It is unthinkable
> > that a thread will find point not in a place where it last moved it.
> 
> It is exactly what happens with current cooperative threads, AFAIK.

With the existing threads, this will never happen, because a thread
will never yield between moving point to some position and accessing
buffer text at that position.

> Will it make sense to convert PT, ZV, and BEGV into thread-local variables?

What do you expect redisplay to do when some thread moves point in a
way that it is no longer in the window?

> >> Is it buffer's marker list? I thought that you are referring to
> >> BUF_MARKERS, not to PT, BEGV, and ZV.
> >
> > Buffer's marker list are referenced in subroutines of
> > record_buffer_markers.
> 
> Do you mean record_buffer_markers->set_marker_both->attach_marker->
>   if (m->buffer != b)
>     {
>       unchain_marker (m);
>       m->buffer = b;
>       m->next = BUF_MARKERS (b);
>       BUF_MARKERS (b) = m;
>     }
> 
> But will this `if' ever trigger for PT, BEGV, and ZV?

I don't know!  You cannot possibly have code where you need to reason
about every single line whether something can or cannot happen there.
You need a relatively small set of basic assumptions that _always_
hold.  Anything more complex makes the task of developing and
maintaining this code an impossible job.

> Also, it looks reasonable to block BUF_MARKERS when we need to change
> BUF_MARKERS.

Sure.  Like I said: we'd need to lock everything.



  reply	other threads:[~2023-07-08 14:43 UTC|newest]

Thread overview: 192+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-04 16:58 Concurrency via isolated process/thread Ihor Radchenko
2023-07-04 17:12 ` Eli Zaretskii
2023-07-04 17:29   ` Ihor Radchenko
2023-07-04 17:35     ` Eli Zaretskii
2023-07-04 17:52       ` Ihor Radchenko
2023-07-04 18:24         ` Eli Zaretskii
2023-07-05 11:23           ` Ihor Radchenko
2023-07-05 11:49             ` Eli Zaretskii
2023-07-05 12:40               ` Ihor Radchenko
2023-07-05 13:02                 ` Lynn Winebarger
2023-07-05 13:10                   ` Ihor Radchenko
2023-07-06 18:35                     ` Lynn Winebarger
2023-07-07 11:48                       ` Ihor Radchenko
2023-07-05 13:33                 ` Eli Zaretskii
2023-07-05 13:35                   ` Ihor Radchenko
2023-07-05  0:34         ` Po Lu
2023-07-05 11:26           ` Ihor Radchenko
2023-07-05 12:11             ` Po Lu
2023-07-05 12:44               ` Ihor Radchenko
2023-07-05 13:21                 ` Po Lu
2023-07-05 13:26                   ` Ihor Radchenko
2023-07-05 13:51                     ` Eli Zaretskii
2023-07-05 14:00                       ` Ihor Radchenko
2023-07-06  0:32                         ` Po Lu
2023-07-06 10:46                           ` Ihor Radchenko
2023-07-06 12:24                             ` Po Lu
2023-07-06 12:31                               ` Ihor Radchenko
2023-07-06 12:41                                 ` Po Lu
2023-07-06 12:51                                   ` Ihor Radchenko
2023-07-06 12:58                                     ` Po Lu
2023-07-06 13:13                                       ` Ihor Radchenko
2023-07-06 14:13                                         ` Eli Zaretskii
2023-07-06 14:47                                           ` Ihor Radchenko
2023-07-06 15:10                                             ` Eli Zaretskii
2023-07-06 16:17                                               ` Ihor Radchenko
2023-07-06 18:19                                                 ` Eli Zaretskii
2023-07-07 12:04                                                   ` Ihor Radchenko
2023-07-07 13:16                                                     ` Eli Zaretskii
2023-07-07 14:29                                                       ` Ihor Radchenko
2023-07-07 14:47                                                         ` Eli Zaretskii
2023-07-07 15:21                                                           ` Ihor Radchenko
2023-07-07 18:04                                                             ` Eli Zaretskii
2023-07-07 18:24                                                               ` Ihor Radchenko
2023-07-07 19:36                                                                 ` Eli Zaretskii
2023-07-07 20:05                                                                   ` Ihor Radchenko
2023-07-08  7:05                                                                     ` Eli Zaretskii
2023-07-08 10:53                                                                       ` Ihor Radchenko
2023-07-08 14:26                                                                         ` Eli Zaretskii
2023-07-09  9:36                                                                           ` Ihor Radchenko
2023-07-09  9:56                                                                             ` Po Lu
2023-07-09 10:04                                                                               ` Ihor Radchenko
2023-07-09 11:59                                                                             ` Eli Zaretskii
2023-07-09 13:58                                                                               ` Ihor Radchenko
2023-07-09 14:52                                                                                 ` Eli Zaretskii
2023-07-09 15:49                                                                                   ` Ihor Radchenko
2023-07-09 16:35                                                                                     ` Eli Zaretskii
2023-07-10 11:30                                                                                       ` Ihor Radchenko
2023-07-10 12:13                                                                                         ` Po Lu
2023-07-10 12:28                                                                                           ` Ihor Radchenko
2023-07-10 12:48                                                                                             ` Po Lu
2023-07-10 12:53                                                                                               ` Ihor Radchenko
2023-07-10 13:18                                                                                                 ` Po Lu
2023-07-10 13:09                                                                                         ` Eli Zaretskii
2023-07-10 13:58                                                                                           ` Ihor Radchenko
2023-07-10 14:37                                                                                             ` Eli Zaretskii
2023-07-10 14:55                                                                                               ` Ihor Radchenko
2023-07-10 16:03                                                                                                 ` Eli Zaretskii
2023-07-16 14:58                                                                                 ` Ihor Radchenko
2023-07-17  7:55                                                                                   ` Ihor Radchenko
2023-07-17  8:36                                                                                     ` Po Lu
2023-07-17  8:52                                                                                       ` Ihor Radchenko
2023-07-17  9:39                                                                                         ` Po Lu
2023-07-17  9:54                                                                                           ` Ihor Radchenko
2023-07-17 10:08                                                                                             ` Po Lu
2023-07-24  8:42                                                                                 ` Ihor Radchenko
2023-07-24  9:52                                                                                   ` Po Lu
2023-07-24 10:09                                                                                     ` Ihor Radchenko
2023-07-24 12:15                                                                                       ` Po Lu
2023-07-24 12:25                                                                                         ` Ihor Radchenko
2023-07-24 13:31                                                                                           ` Po Lu
2023-07-24 13:53                                                                                             ` Ihor Radchenko
2023-07-25  0:12                                                                                               ` Po Lu
2023-07-25  4:28                                                                                                 ` Ihor Radchenko
2023-07-24 12:50                                                                                       ` Eli Zaretskii
2023-07-24 13:15                                                                                         ` Ihor Radchenko
2023-07-24 13:41                                                                                           ` Eli Zaretskii
2023-07-24 14:13                                                                                             ` Ihor Radchenko
2023-07-24 12:44                                                                                   ` Eli Zaretskii
2023-07-24 13:02                                                                                     ` Ihor Radchenko
2023-07-24 13:54                                                                                       ` Eli Zaretskii
2023-07-24 14:24                                                                                         ` Ihor Radchenko
2023-07-24 16:00                                                                                           ` Eli Zaretskii
2023-07-24 16:38                                                                                             ` Ihor Radchenko
2023-07-25  0:20                                                                                               ` Po Lu
2023-07-25  4:36                                                                                                 ` Ihor Radchenko
2023-07-25  7:27                                                                                                   ` Po Lu
2023-07-25  7:59                                                                                                     ` Ihor Radchenko
2023-07-25  8:27                                                                                                       ` Po Lu
2023-07-25  8:45                                                                                                         ` Ihor Radchenko
2023-07-25  8:53                                                                                                           ` Po Lu
2023-07-25  9:03                                                                                                             ` Ihor Radchenko
2023-07-25  9:17                                                                                                               ` Po Lu
2023-07-25  9:27                                                                                                                 ` Ihor Radchenko
2023-07-25  9:37                                                                                                                   ` Po Lu
2023-07-25 12:40                                                                                                                   ` Eli Zaretskii
2023-07-25 11:29                                                                                               ` Eli Zaretskii
2023-07-25 11:52                                                                                                 ` Ihor Radchenko
2023-07-25 14:27                                                                                                   ` Eli Zaretskii
2023-07-09 17:13                                                                             ` Gregory Heytings
2023-07-10 11:37                                                                               ` Ihor Radchenko
2023-07-13 13:54                                                                                 ` Gregory Heytings
2023-07-13 14:23                                                                                   ` Ihor Radchenko
2023-07-07  0:21                                         ` Po Lu
2023-07-06 14:08                             ` Eli Zaretskii
2023-07-06 15:01                               ` Ihor Radchenko
2023-07-06 15:16                                 ` Eli Zaretskii
2023-07-06 16:32                                   ` Ihor Radchenko
2023-07-06 17:50                                     ` Eli Zaretskii
2023-07-07 12:30                                       ` Ihor Radchenko
2023-07-07 13:34                                         ` Eli Zaretskii
2023-07-07 15:17                                           ` Ihor Radchenko
2023-07-07 19:31                                             ` Eli Zaretskii
2023-07-07 20:01                                               ` Ihor Radchenko
2023-07-08  6:50                                                 ` Eli Zaretskii
2023-07-08 11:55                                                   ` Ihor Radchenko
2023-07-08 14:43                                                     ` Eli Zaretskii [this message]
2023-07-09  9:57                                                       ` Ihor Radchenko
2023-07-09 12:08                                                         ` Eli Zaretskii
2023-07-09 14:16                                                           ` Ihor Radchenko
2023-07-09 15:00                                                             ` Eli Zaretskii
2023-07-09 12:22                                                         ` Po Lu
2023-07-09 13:12                                                           ` Eli Zaretskii
2023-07-10  0:18                                                             ` Po Lu
2023-07-08  0:51                                               ` Po Lu
2023-07-08  4:18                                                 ` tomas
2023-07-08  5:51                                                   ` Po Lu
2023-07-08  6:01                                                     ` tomas
2023-07-08 10:02                                                       ` Ihor Radchenko
2023-07-08 19:39                                                         ` tomas
2023-07-08  6:25                                                 ` Eli Zaretskii
2023-07-08  6:38                                                   ` Ihor Radchenko
2023-07-08  7:45                                                     ` Eli Zaretskii
2023-07-08  8:16                                                       ` Ihor Radchenko
2023-07-08 10:13                                                         ` Eli Zaretskii
2023-07-07 13:35                                         ` Po Lu
2023-07-07 15:31                                           ` Ihor Radchenko
2023-07-08  0:44                                             ` Po Lu
2023-07-08  4:29                                               ` tomas
2023-07-08  7:21                                               ` Eli Zaretskii
2023-07-08  7:48                                                 ` Po Lu
2023-07-08 10:02                                                   ` Eli Zaretskii
2023-07-08 11:54                                                     ` Po Lu
2023-07-08 14:12                                                       ` Eli Zaretskii
2023-07-09  0:37                                                         ` Po Lu
2023-07-09  7:01                                                           ` Eli Zaretskii
2023-07-09  7:14                                                             ` Po Lu
2023-07-09  7:35                                                               ` Eli Zaretskii
2023-07-09  7:57                                                                 ` Ihor Radchenko
2023-07-09  8:41                                                                   ` Eli Zaretskii
2023-07-10 14:53                                                                     ` Dmitry Gutov
2023-07-09  9:25                                                                 ` Po Lu
2023-07-09 11:14                                                                   ` Eli Zaretskii
2023-07-09 11:23                                                                     ` Ihor Radchenko
2023-07-09 12:10                                                                     ` Po Lu
2023-07-09 13:03                                                                       ` Eli Zaretskii
2023-07-08 12:01                                                     ` Ihor Radchenko
2023-07-08 14:45                                                       ` Eli Zaretskii
2023-07-07  0:41                                     ` Po Lu
2023-07-07 12:42                                       ` Ihor Radchenko
2023-07-07 13:31                                         ` Po Lu
2023-07-07  0:27                                 ` Po Lu
2023-07-07 12:45                                   ` Ihor Radchenko
2023-07-06  0:27                     ` Po Lu
2023-07-06 10:48                       ` Ihor Radchenko
2023-07-06 12:15                         ` Po Lu
2023-07-06 14:10                         ` Eli Zaretskii
2023-07-06 15:09                           ` Ihor Radchenko
2023-07-06 15:18                             ` Eli Zaretskii
2023-07-06 16:36                               ` Ihor Radchenko
2023-07-06 17:53                                 ` Eli Zaretskii
2023-07-07  0:22                             ` Po Lu
2023-07-05  0:33 ` Po Lu
2023-07-05  2:31   ` Eli Zaretskii
2023-07-17 20:43     ` Hugo Thunnissen
2023-07-18  4:51       ` tomas
2023-07-18  5:25       ` Ihor Radchenko
2023-07-18  5:39         ` Po Lu
2023-07-18  5:49           ` Ihor Radchenko
2023-07-18 12:14         ` Hugo Thunnissen
2023-07-18 12:39           ` Async IO and queing process sentinels (was: Concurrency via isolated process/thread) Ihor Radchenko
2023-07-18 12:49             ` Ihor Radchenko
2023-07-18 14:12             ` Async IO and queing process sentinels Michael Albinus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=838rbqcvlx.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=luangruo@yahoo.com \
    --cc=yantar92@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).