From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.devel Subject: Re: Concurrency via isolated process/thread Date: Fri, 07 Jul 2023 15:17:23 +0000 Message-ID: <87lefrbvjw.fsf@localhost> References: <871qhnr4ty.fsf@localhost> <87v8ezpov0.fsf@localhost> <83r0pnk2az.fsf@gnu.org> <87pm57pns8.fsf@localhost> <87lefvp55t.fsf@yahoo.com> <87sfa28ura.fsf@localhost> <87cz16o8vz.fsf@yahoo.com> <87jzve8r4m.fsf@localhost> <871qhmo5nv.fsf@yahoo.com> <87bkgq8p5t.fsf@localhost> <831qhmjwk0.fsf@gnu.org> <875y6y8nlr.fsf@localhost> <87h6qhnalc.fsf@yahoo.com> <87ilax71wo.fsf@localhost> <831qhli14t.fsf@gnu.org> <87wmzdxewc.fsf@localhost> <83r0plgjeo.fsf@gnu.org> <87o7kpxapo.fsf@localhost> <83mt09gcaf.fsf@gnu.org> <87wmzbc3af.fsf@localhost> <83cz13g811.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5868"; mail-complaints-to="usenet@ciao.gmane.io" Cc: luangruo@yahoo.com, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Jul 07 17:18:42 2023 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 1qHnEH-0001K9-A7 for ged-emacs-devel@m.gmane-mx.org; Fri, 07 Jul 2023 17:18:41 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHnDA-0000uP-K1; Fri, 07 Jul 2023 11:17:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qHnD8-0000tZ-5M for emacs-devel@gnu.org; Fri, 07 Jul 2023 11:17:30 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qHnD3-0000au-Uu for emacs-devel@gnu.org; Fri, 07 Jul 2023 11:17:29 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 0A2F4240106 for ; Fri, 7 Jul 2023 17:17:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1688743043; bh=QW4rgDKAWppfQ//PYMa0MvLvGV16T1d0DlN2ZlRzj7g=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=bee9MLmx/9LDwy2CXruiJuw+Fe93f4Hscl3Snyw6jxTx6uIW4DOug2HRF3w9OX+DK crlKAyvq6d1nA/LdkggP+sVXtIx9a1a3YUSr8AyD5nkfnN+NxIkNWo8gjYEtmc6v6q +q0ysIpyTMy9W4U2ZHxeKdWlWwITEhdHcfgcgYKbDYHZ9/TF+QFwvvuE1rpGlSN5d0 /MymxuO9k61OBN21FvVZXcxJP6IgeKjRkyyfeIF05vUOeCgwwnMrsMLuVfpUBoU7d3 /MtBH/9HVVko0Hs6MP5qcFbBQVVr7/ukBdho7TDFhGP9SwuV4M0w5SZZTVHS6qcEEo 6A9kJ0h4gDAHw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4QyH7k189Vz9rxR; Fri, 7 Jul 2023 17:17:21 +0200 (CEST) In-Reply-To: <83cz13g811.fsf@gnu.org> Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:307580 Archived-At: Eli Zaretskii writes: >> maybe need to have multiple heaps. > > All modern implementation of malloc already do use several different > heaps internally. I was talking about Elisp heaps. AFAIU, Elisp memory management is conceptually single-threaded. >> I was only able to identify the following: >> >> interrupt_input_blocked >> current_buffer >> last_known_column_point > > There are much more: > > buffer-alist I do not see how this is a problem to lock/unlock this variable. > buffer's base-buffer I do not see it. May you point me to where this is changed? > buffer's undo-list That's just a synchronization between old_buffer and old_buffer->base_buffer. I am not 100% sure why it is necessary to be done this way and manually instead of making undo-list values in indirect buffers point to base buffer. > buffer's point and begv/zv markers AFAIU, these store the last point position and narrowing state. I do not see much problem here, except a need to lock these variables while writing them. They will not affect PT, BEGZ, and ZV in other threads, even if those operate on the same buffer now. > buffer's marker list May you point me where it is? > buffer's local variables I admit that I do not understand what the following comment is talking about: /* Look down buffer's list of local Lisp variables to find and update any that forward into C variables. */ >> AFAIU, current_buffer might be made thread-local and >> last_known_column_point can be made buffer-local. > > The current buffer is already thread-local. Thanks for the pointer. I did not expect #define current_buffer (current_thread->m_current_buffer) >> interrupt_input_blocked is more tricky. But it is just one global state >> variable. Surely we can find a solution to make it work with multiple threads. > > Yes, but we have just looked at a single primitive: set-buffer. Once > in the buffer, any useful Lisp program will do gobs of stuff, and each > one of those accesses more and more globals. How do you protect all > that in a 100% reliable way? by identifying the variables and > structures one by one? what if tomorrow some change in Emacs adds one > more? This sounds like a problem that is already solved by any program that uses async threads. Maybe Po Lu can provide good insights. >> > I think you misunderstand the frequency of such collisions. >> > case-fold-search comes to mind. >> >> How so? What is the problem with a buffer-local variable that is rarely >> set directly (other than by major modes)? let-binding is common, but it >> is not a problem. > > Searching for "setq case-fold-search" finds more than 30 hits in Emacs > alone. And this variable is just an example. These are mostly major/minor modes and constructs like (setq case-fold-search ...) (do staff) (setq case-fold-search old-value) The last one is legitimate problem with logic. Although not much different from Elisp threads doing the same and changing buffer-local variables in the midst of other thread running in the same buffer. So, I do not see how this should prevent async threads. We just need to take care about setq not attempting to write into buffer-local variables at the same time, which is solved by locking. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at