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.bugs Subject: bug#57196: 28.1.90; An idea to allow background (low-priority) threads Date: Sun, 14 Aug 2022 10:02:58 +0300 Message-ID: <83bksnl331.fsf@gnu.org> References: <878rnr1n17.fsf@localhost> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18766"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 57196@debbugs.gnu.org To: Ihor Radchenko Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Aug 14 09:04:45 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 1oN7fw-0004dg-9h for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 14 Aug 2022 09:04:44 +0200 Original-Received: from localhost ([::1]:46862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oN7fu-0007rz-C0 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 14 Aug 2022 03:04:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oN7fH-0007q9-Si for bug-gnu-emacs@gnu.org; Sun, 14 Aug 2022 03:04:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45951) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oN7fG-0006oS-MZ for bug-gnu-emacs@gnu.org; Sun, 14 Aug 2022 03:04:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oN7fF-0000RR-S0 for bug-gnu-emacs@gnu.org; Sun, 14 Aug 2022 03:04:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 14 Aug 2022 07:04:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57196 X-GNU-PR-Package: emacs Original-Received: via spool by 57196-submit@debbugs.gnu.org id=B57196.16604606061654 (code B ref 57196); Sun, 14 Aug 2022 07:04:01 +0000 Original-Received: (at 57196) by debbugs.gnu.org; 14 Aug 2022 07:03:26 +0000 Original-Received: from localhost ([127.0.0.1]:35700 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oN7eg-0000Qc-8l for submit@debbugs.gnu.org; Sun, 14 Aug 2022 03:03:26 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:36846) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oN7ea-0000QM-Sn for 57196@debbugs.gnu.org; Sun, 14 Aug 2022 03:03:24 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:40428) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oN7eV-0006mJ-Jx; Sun, 14 Aug 2022 03:03:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=F2NIhthpWG11wQdbLuOKeeSbhy5U2VDeTAhn3VRLmRk=; b=UpAXPTYNYPcS KCE06Y98yJ2VwauWWf79vzlOCnJAy5n+mUkOSqMCO/leXV7GmUa9fjWUxJuctPZAhTBcEY2WV437l vNMzWoDifvSKY4z10MRQdo8W9lFLq4NEjoJ2rSC7YywpORxvDgjoUfkS/NsFOjGnZ975c2+OW7yjo KalLDj6XTOPFCYXwuDoSrQxqhOyTELoHst99GE9iubctK0Zr0CIIC0BnSqoawSiYCbpD+qJkvcTcF miuOysnddMeOxwrvBWhcqVlbiEwBRHcjAomcdVu2uFH7QZYMXXRQFkkdCASVlYEdk/PqaslNM/EPP pEsWphBat9pJkz3SR1I9dg==; Original-Received: from [87.69.77.57] (port=1530 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 1oN7eV-0006mb-2G; Sun, 14 Aug 2022 03:03:15 -0400 In-Reply-To: <878rnr1n17.fsf@localhost> (message from Ihor Radchenko on Sun, 14 Aug 2022 12:12:20 +0800) 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:239623 Archived-At: > From: Ihor Radchenko > Date: Sun, 14 Aug 2022 12:12:20 +0800 > > 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? Our "scheduler", such as it is, is in thread.c:really_call_select. It basically releases the global lock and lets the first thread waiting on the lock to acquire the lock. If someone wants to implement a smarter lock-grabbing logic with some kind of "nice" capability, AFAIU that's the place to look and modify. TBH, I'm not really sure your analysis, which basically says this is a problem with thread "equality", is correct. Did you try to see what causes the sluggish operation in the cases where you saw it? > 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. What mechanism will stop the running thread that has exceeded its allotted time? In the current implementation, the thread stops itself when it calls a small set of primitives, but with your proposal we'd need to make the "scheduler" run in a separate thread, which would mean a complete redesign of how threads are scheduled.