From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philipp Newsgroups: gmane.emacs.help Subject: Re: Is automatic yield support feasible for threads? Date: Thu, 11 Nov 2021 19:11:10 +0100 Message-ID: <34FDD154-0DF4-4163-8B35-00DE4A7B30DD@gmail.com> References: <46501A5F-9C72-4048-8EEA-CE219D54CEC2@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.20.0.1.32\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9889"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "help-gnu-emacs@gnu.org" To: ndame Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 11 19:11:50 2021 Return-path: Envelope-to: geh-help-gnu-emacs@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 1mlEYA-0002NO-2H for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 11 Nov 2021 19:11:50 +0100 Original-Received: from localhost ([::1]:46436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mlEY8-0002lj-6T for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 11 Nov 2021 13:11:48 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:57368) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mlEXb-0002k4-0m for help-gnu-emacs@gnu.org; Thu, 11 Nov 2021 13:11:15 -0500 Original-Received: from [2a00:1450:4864:20::429] (port=36790 helo=mail-wr1-x429.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mlEXZ-0004xn-Am for help-gnu-emacs@gnu.org; Thu, 11 Nov 2021 13:11:14 -0500 Original-Received: by mail-wr1-x429.google.com with SMTP id s13so11249834wrb.3 for ; Thu, 11 Nov 2021 10:11:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=2D3/dp2NV5Oa+lqeQOGfm4VazXiQMr/H7GZ47nXahNc=; b=QrCxXoYnWZA6A/7ZaSgklb/2AwCiOMb/sww7QveslGVLMofFuitlq6rLDwRKDDShNe JufAlKkY+0NzYLxMj+5JYV/o8d4+jJFmbfzaKaRxr+1nl3GFWkAcDraF8xrThcVfUMDN CBVWQJz36Myp2tawDBX9enabAH/WZLiaEv31+AMmbcrsnB5fvLenot875wP5BD4oEtJZ T2+CFFibl227pvCF92y4AyAvvfqtGx7Jwx/bl1Tu6h5k479JIfvEVLG0s6sF2bqL9EFb mhGfqiCVzh5hZqmnzSURX0tb/yyrPTWjSqX//3jyaQ+3Zacvxm7LUcpHTaIqhJEui2FN OBRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=2D3/dp2NV5Oa+lqeQOGfm4VazXiQMr/H7GZ47nXahNc=; b=Tk8YpYBxvSK01cwtCx6NfTg3HJMD5eHteiq4gYEazYbhKqGugNDfsHgyVLiKP5j+w7 DPLYoUnJS7au/AIJA1Xmw2zc/8gn2+4FBNIKyOOdNl5VTcoHMkeug6Y4AyC237a1IKjv 5bl0lycbAEn4xQU+4I4LiqhoHqPrdfmglM8xAgV7OrQQFAIFgx+hzU+ybWFSQpQV2dTP ZX5GwqdZwf4EiZZ3t3kp0QiuefM2z/VoI018UG4vwutuWaq6JC2oGYN3NGuF0BVU2lIa kfbr5eULYZQZJaYvRYBTEWP+DT0xbwiTZLmSw4dteBPDg0PbM27MqYmuB1FZhZB7mMyd xgMA== X-Gm-Message-State: AOAM530bdSX4clM69iaqhhzue0P5PlG3vzcm3txuWL58+ypYA38aMsnW J10zY6lByK5P5CYtUSD8uPoO4yzv5vc= X-Google-Smtp-Source: ABdhPJzE2Q4qEifauFUt4hS/04ts6wGxYkEK6UE4Lo3uXkuK8tcCuKyjqbOw+TTMGTnOqf72cHPGkw== X-Received: by 2002:a5d:6707:: with SMTP id o7mr10908710wru.172.1636654271507; Thu, 11 Nov 2021 10:11:11 -0800 (PST) Original-Received: from smtpclient.apple (p579970db.dip0.t-ipconnect.de. [87.153.112.219]) by smtp.gmail.com with ESMTPSA id h15sm10334615wmq.32.2021.11.11.10.11.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Nov 2021 10:11:11 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3693.20.0.1.32) X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::429 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=p.stephani2@gmail.com; helo=mail-wr1-x429.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:134492 Archived-At: > Am 10.11.2021 um 08:46 schrieb ndame : >=20 > On Tuesday, November 9th, 2021 at 3:53 PM, Philipp = wrote: >>=20 >> I don't think it's feasible. Emacs Lisp code typically relies heavily = on mutating global state (think buffer contents, the buffer list, = `point', dynamic variables, ...), and normally doesn't put such state = mutations into properly synchronized critical sections. Yielding from = such unprotected critical sections would result in very subtle bugs = (`point' randomly moving around, corruption of internal data structures, = buffers vanishing surprisingly, ...). >=20 > I don't think threads should be used for UI manipulation, that should = be left for the main thread. Threads are more useful for longer running = calculations, computations and those should have no problem if they work = on local data. There are two problems with that approach: 1. Emacs doesn't clearly separate UI work from non-UI work. For = example, buffers are primarily a UI feature, but are also widely used = for string manipulation unrelated to any UI action, and such uses are = typically considered implementation details. 2. There are many coding patterns involving global state mutations that = are unrelated to UI actions, e.g., caching the result of an expensive = computation. >=20 > But you are right if someone uses a thread for UI changes then there = can be problems. My idea is about an _optional_ automatic yielding for = threads, so it still could be useful for those threads which are self = contained. Only trivial thread bodies are guaranteed to be self-contained. You'd = need to audit every single function that the thread body calls whether = it performs any unsynchronized global state mutations, which is = infeasible since such state mutations are generally considered = implementation details, and functions typically don't document them.