From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.devel Subject: Re: Releasing the thread global_lock from the module API Date: Sat, 2 Mar 2024 17:35:26 +0200 Message-ID: <19d51eaa-0f98-4542-9d08-0e9d23224dc4@gutov.dev> References: <86cysdrja3.fsf@gnu.org> <470c6bea-805d-42dd-8bbd-936ea93c6579@gutov.dev> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33363"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: Spencer Baugh , emacs-devel@gnu.org To: tomas@tuxteam.de Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Mar 02 16:36:27 2024 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 1rgRPW-0008PT-Mo for ged-emacs-devel@m.gmane-mx.org; Sat, 02 Mar 2024 16:36:27 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rgROo-0006ob-98; Sat, 02 Mar 2024 10:35:42 -0500 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 1rgROm-0006kp-65 for emacs-devel@gnu.org; Sat, 02 Mar 2024 10:35:40 -0500 Original-Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rgROc-00086e-LT for emacs-devel@gnu.org; Sat, 02 Mar 2024 10:35:37 -0500 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 0A10D5C0056; Sat, 2 Mar 2024 10:35:29 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sat, 02 Mar 2024 10:35:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1709393729; x=1709480129; bh=Ga+BddclGvjkjcTrZq6IRRYQFfb0zqW/M5cO5par0J4=; b= R6TY9xrK3wazF79nQ6NWSgKCqBIpGW8mhaxhTMZ3Ct+Urzc144L+bdqj4Gm7vs7e qwjQJI0drZ83Yfbhbzm4WJQLFLe4ZjbIK0RxafLQolU4Iwofw9QWe0zWtEnmhcB5 5u8D8xqXB1opBQaQmDCv37vXLXIsCEmZfjex+6YL0Q/HvxN1ixsGCyocQWKNYxzl wl26ySBPbK172YDWcNY+dGqAjPlNPCtVuKWDx+YRQIZoJa9W/7Bw9Hy2j2DD+/Nx NeqEZJMQbf4rk6YJTfKM84LNBN/pZqOyib09cEkhdnCPJQvYX6qw5jR7WPnNy5Ih dFASpQfASOKN0TcxexkUPw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1709393729; x= 1709480129; bh=Ga+BddclGvjkjcTrZq6IRRYQFfb0zqW/M5cO5par0J4=; b=R CChOEGDnRSA8qINL2jretWIcXMf7oqPQe0z3VpxtQHh5HTHkYLAMC2LbASkOGqrY 3oigigYl6C9SYOB0sMDnBDg+CaufzdBLsa/GQW3JrjMfpuIS+hrG02RWzDPaf0NU +S15Vx8sUe8sq1kTG+eoefUBsunrfPZcbYTMwpu4AKIcmzGVU8PQJfVYHzHQorSH wdZfojJkGxfGx8d6jNUX57xTMgKbfm7G3l75FgjVxR9pPcEb9LcEgnJLygXxyLX9 NiREvEV+8/t1/5aIC9N3pNjySNZwhnmjcC7btLzAQ/ho4qz9J6dGakdyHthEFHJW JljoekCxbyBpD4TLiXHow== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrheefgdejjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfuvfevfhfhjggtgfesthejredttddvjeenucfhrhhomhepffhmihht rhihucfiuhhtohhvuceoughmihhtrhihsehguhhtohhvrdguvghvqeenucggtffrrghtth gvrhhnpeetudeljeegheetgfehgeejkeeuhedvveeikeeufedtvddtveefhfdvveegudej heenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegumh hithhrhiesghhuthhovhdruggvvh X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 2 Mar 2024 10:35:27 -0500 (EST) Content-Language: en-US In-Reply-To: Received-SPF: pass client-ip=66.111.4.25; envelope-from=dmitry@gutov.dev; helo=out1-smtp.messagingengine.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: 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:316696 Archived-At: On 02/03/2024 07:57, tomas@tuxteam.de wrote: > On Sat, Mar 02, 2024 at 01:53:05AM +0200, Dmitry Gutov wrote: >> On 01/03/2024 21:30, tomas@tuxteam.de wrote: >>>> - Unrelated Lisp thread B is able to take the global lock and run Lisp code >>>> in parallel with module_work on thread A. >>>> - On thread A, module_work finishes and returns to Lisp. >>> Why has thread A wait up to here? This is what's keeping your thread B >>> from playing, no? >> >> I imagine thread A will want to continue its execution when the results of >> the "Emacs-independent work" arrive. > > In that case, I think your only choice would be to "pass the continuation": > in A, stash away whatever you need to continue, let A die, and when things > "come back", start a thread A' to pick up where A left. Almost, except "suspend/yield" instead of "let A die". And if the Lisp threads are backed by OS threads, such thread is waiting without purpose while "suspended" - Spencer's suggestion could put it to work in the meantime as well. Though the difference in performance might not be very significant, given our overhead in other places. >> Said work might look like making a network request (as Spencer outlined), >> getting a response, parsing the received JSON structure (not into Lisp >> objects yet, just into the native data structures provided by the library), >> and potentially filtering the parsed structure as well. >> >> Then the lock is re-acquired (which will naturally involve some spinning >> waiting for it), and the parsed data is converted into Lisp structures. > > I'm always wary when people call for "threads" when they mean concurrency. Yes, our Lisp threads are a bit unusual, terminology-wise.