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 12:04:36 +0000 Message-ID: <87zg48apwr.fsf@localhost> References: <871qhnr4ty.fsf@localhost> <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> <878rbtkz2c.fsf@yahoo.com> <87a5w96x2o.fsf@localhost> <87jzvdjjp4.fsf@yahoo.com> <877crd6w53.fsf@localhost> <877crdjiwn.fsf@yahoo.com> <874jmh6v4s.fsf@localhost> <83y1jtgmbw.fsf@gnu.org> <87zg49xfke.fsf@localhost> <83sfa1gjns.fsf@gnu.org> <87r0plxbep.fsf@localhost> <83ilawhpi6.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="9308"; 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 14:06:10 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 1qHkDy-0002F8-Ew for ged-emacs-devel@m.gmane-mx.org; Fri, 07 Jul 2023 14:06:10 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qHkCa-0001pK-Cc; Fri, 07 Jul 2023 08:04:44 -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 1qHkCY-0001pA-BO for emacs-devel@gnu.org; Fri, 07 Jul 2023 08:04:42 -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 1qHkCV-0003ic-Lr for emacs-devel@gnu.org; Fri, 07 Jul 2023 08:04:42 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 1E52E240103 for ; Fri, 7 Jul 2023 14:04:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1688731476; bh=6c0NBdGE1TtB2cGsJX/XwRbBBA11rKrrarn7GyNWW9I=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=UcIi778bkqidp5TT5tmPGp3EpWxXjpWqI9LzPVB/ShNc/sgp1PGbHkA0aWdmC7rfe PMW2g/JzJzhUcPzuXQ+TP1tFyNTe9sRvC4Yi6YH+jsUijJbTbUaNRaY7ZVRuPTSfgm SdQ2iOsXYODqp7BmzFAX/CPPs+7r05/XuBlDiWpM7vRdcpi4ZjeafJOgNENwWCBEUN 509M+uTlsrRLkUYyGXwPcUQMkMD4buFF0wNK2uSkZBaqIY5f6i0IeP88xTn6chDLqy JID3KPN1TU2FePrVPoYuRcy4hxFleXcfurwPmW3bmFlt0BzC1OtLKQhqeOvt1L7OfO SZH1FW6CuMnXA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4QyBsH32bgz6tsb; Fri, 7 Jul 2023 14:04:35 +0200 (CEST) In-Reply-To: <83ilawhpi6.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=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:307560 Archived-At: Eli Zaretskii writes: >> > That could defeat GC, should Emacs decide to run it while the lock is >> > in place. >> >> May you elaborate? > > GC doesn't only free memory used by dead objects. It also performs > bookkeeping on live objects: compacts data of strings, relocates text > of buffers, compacts the gap in buffers where it became too large, > etc. This bookkeeping is more important when Emacs is short on > memory: in those cases these bookkeeping tasks might mean the > difference between being able to keep the session healthy enough to > allow the user to shut down in an orderly fashion. What you are describing will only affect subr primitives that work directly with C structs and address space. So, we can distinguish two locks: (1) low-level, only available to C subroutines; (2) Elisp-level, where the lock merely prevents other Elisp code from modifying the data. GC is safe to run when type-2 lock is in place as it will never clear the data in use and never alter the data in any way visible on Elisp level. > Locking objects means these bookkeeping tasks will be disabled. That > could adversely affect the available memory and the memory footprint > in general. I do not think that it is that bad if we consider type-1 locks. Consider two parallel threads: ----- 1 ------ (let ((i 0)) (while t (cl-incf i))) -------------- ----- 2 ----- (while t (read-char)) ------------- Both the threads will call eval_sub frequently that will trigger maybe_gc. I consider that maybe_gc, when decided that GC is necessary, but cannot continue because an object is locked using type-1 lock, will pause the current thread. Let's consider the current thread to be thread 2 paused because thread 1 is doing (setq i ...) at the same time and locked object corresponding to obarray variable slot for "i". Thread 1 will continue executing until (very soon) it calls maybe_gc itself. This time, no further object lock is active and gc may proceed, continuing both the threads once GC is done. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at