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.bugs Subject: bug#57196: 28.1.90; An idea to allow background (low-priority) threads Date: Sun, 14 Aug 2022 12:12:20 +0800 Message-ID: <878rnr1n17.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32958"; mail-complaints-to="usenet@ciao.gmane.io" To: 57196@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Aug 14 06:13:05 2022 Return-path: Envelope-to: geb-bug-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 1oN4zp-0008Pu-FJ for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 14 Aug 2022 06:13:05 +0200 Original-Received: from localhost ([::1]:42200 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oN4zo-00020U-6Z for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 14 Aug 2022 00:13:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35052) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oN4yr-00020M-TR for bug-gnu-emacs@gnu.org; Sun, 14 Aug 2022 00:12:06 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45823) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oN4yp-0001bQ-Mn for bug-gnu-emacs@gnu.org; Sun, 14 Aug 2022 00:12:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oN4yo-0001xV-IC for bug-gnu-emacs@gnu.org; Sun, 14 Aug 2022 00:12:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ihor Radchenko Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 14 Aug 2022 04:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 57196 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16604502917483 (code B ref -1); Sun, 14 Aug 2022 04:12:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 14 Aug 2022 04:11:31 +0000 Original-Received: from localhost ([127.0.0.1]:35571 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oN4yI-0001wc-KC for submit@debbugs.gnu.org; Sun, 14 Aug 2022 00:11:31 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:57738) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oN4yD-0001wS-TM for submit@debbugs.gnu.org; Sun, 14 Aug 2022 00:11:29 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oN4yD-0001xh-Ou for bug-gnu-emacs@gnu.org; Sun, 14 Aug 2022 00:11:25 -0400 Original-Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:41675) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oN4y9-0001ZQ-My for bug-gnu-emacs@gnu.org; Sun, 14 Aug 2022 00:11:25 -0400 Original-Received: by mail-pj1-x102e.google.com with SMTP id t2-20020a17090a4e4200b001f21572f3a4so4208724pjl.0 for ; Sat, 13 Aug 2022 21:11:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:subject:to:from:from:to:cc; bh=xzLtSQKIjtohDfUE0vp4ZJ5HCVWKQz0KJQVoB8wUcWE=; b=BpzKSum2bOwnIhMWQ2Dw+bhorGU2EFs6hUJw9mbBDhg3tpGLn5Ghq+LoQsy+ZGNx7Y +rZKMBT0anj8bL7SHmKdgCfn1iIJcAeFQbB6iby/PbED8lCA8bHwrRPPJxyhm1UZZwQ7 SgGQf4P+uZ3JWoiN+49MRIayVkMTwH+k5KGylVL5tSI3LobWLsiaj4LPifhdHwn+sNvA p6NolKyoogAZ8WxDRsBvldcgWyXRtUysgCXu+I8BkyXXdYV3LYiBEuHPSNPcsd2hNbfn zUo5RxA5StfEqhCxTJw3trNvn67X8Svmf+x5k9hsgdjb/tuDj2ejU6E2MNK6cdP5/l7x uzJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc; bh=xzLtSQKIjtohDfUE0vp4ZJ5HCVWKQz0KJQVoB8wUcWE=; b=m+Fwd6atXPEv0TweHR1y2dbjWZ9jEzCdt2eDi4rwacyTFU3RB9LplnLKtr3qXrnsLI ppzUjklSAPt2Ggg3ZRke3tMsyFWZcQULDBUq8WKTfvnJzkqqd4g5LuPCpl8HHAQjFO2d S5V5BkmIp/HpWofm765wdPsJ4w3PXLUpNv1LNKikw/tdbvsHG/dbfQuatygh3R8tLJkR cCBas/NixNkdpWYnT7EPu/lNf4ho9Ois+ZnR5b7yCCjEyQWQMkEkhqee0CJG8814+KEH KEmNt4A4xSulcZpAKBZ6HH6EEmB71vgdQlhXjqjUXWplTqsWFhnofmsJN1BvKlB8ge2A Ggvg== X-Gm-Message-State: ACgBeo0VxHj1pkTJ9JHMxLpSW7rnTxNwMmus3yr8xnnCTfO89Ad49kv1 Wp9XDrsPmPgRmkTDV0pFUdlrN3wMZiF6rA== X-Google-Smtp-Source: AA6agR67xI3oEVlq0cXy6sEcs55uRpfEeZcjPqUvWUqaHdLo1ehf9LwufhUN6ONG+z9ld0Yel1XcwQ== X-Received: by 2002:a17:90a:9907:b0:1f5:2318:ea6d with SMTP id b7-20020a17090a990700b001f52318ea6dmr12172941pjp.163.1660450279836; Sat, 13 Aug 2022 21:11:19 -0700 (PDT) Original-Received: from localhost ([2409:8a70:2bf:80b0:8ec6:81ff:fe70:339d]) by smtp.gmail.com with ESMTPSA id u20-20020a62d454000000b00534c32592fasm344967pfl.146.2022.08.13.21.11.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Aug 2022 21:11:19 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=yantar92@gmail.com; helo=mail-pj1-x102e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:239608 Archived-At: Hi, Emacs does have a limited concurrency support via Threads, which is, unfortunately, mostly a toy feature I haven't seen being used a lot. All my attempts to implement some real functionality using threads failed because it is very hard to create real-life threads that do not noticeably block Emacs. Most of the time, Emacs gets quite sluggish, even if the thread yields frequently. Such situation sounds similar to what one may get with 1CPU and multiple processed fighting for the CPU time. This is something that used to be solved with nice command. Could something like nice be implemented for Elisp threads? Or, alternatively, could thread execution be limited in some ways? I have the approach taken by org-element cache processing in mind. org-element limits cache processing using the following variables: (defvar org-element-cache-sync-idle-time 0.6 "Length, in seconds, of idle time before syncing cache.") (defvar org-element-cache-sync-duration 0.04 "Maximum duration, as a time value, for a cache synchronization. If the synchronization is not over after this delay, the process pauses and resumes after `org-element-cache-sync-break' seconds.") (defvar org-element-cache-sync-break 0.3 "Duration, as a time value, of the pause between synchronizations. See `org-element-cache-sync-duration' for more information.") I imagine that something similar could be done for threads. `make-thread' could allow some kind of priority setting that will limit its execution time to comfortable levels, so that the user in main thread can actually interact with Emacs without noticing anything. WDYT? -- Ihor Radchenko, Org mode contributor, Learn more about Org mode at https://orgmode.org/. Support Org development at https://liberapay.com/org-mode, or support my work at https://liberapay.com/yantar92