From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: multi-threaded Emacs Date: Thu, 11 Dec 2008 15:53:07 -0500 Message-ID: References: <87abbiody1.fsf@master.homenet> <874p1npvtj.fsf@master.homenet> <87ej0qci8g.fsf@master.homenet> <87y6yxm7xr.fsf@master.homenet> <87hc5gyn9x.fsf@master.homenet> <87ej0ixx97.fsf@master.homenet> <86skouwz8u.fsf@lifelogs.com> <86tz9asgdv.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1229029495 29099 80.91.229.12 (11 Dec 2008 21:04:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Dec 2008 21:04:55 +0000 (UTC) Cc: emacs-devel@gnu.org To: Ted Zlatanov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Dec 11 22:05:59 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LAsj1-0004Se-G3 for ged-emacs-devel@m.gmane.org; Thu, 11 Dec 2008 22:05:51 +0100 Original-Received: from localhost ([127.0.0.1]:56784 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LAsho-0004ji-PL for ged-emacs-devel@m.gmane.org; Thu, 11 Dec 2008 16:04:20 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LAsXG-0007z9-U5 for emacs-devel@gnu.org; Thu, 11 Dec 2008 15:53:26 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LAsXD-0007xo-Ui for emacs-devel@gnu.org; Thu, 11 Dec 2008 15:53:26 -0500 Original-Received: from [199.232.76.173] (port=36192 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LAsXD-0007xj-Q8 for emacs-devel@gnu.org; Thu, 11 Dec 2008 15:53:23 -0500 Original-Received: from ironport2-out.pppoe.ca ([206.248.154.182]:19488 helo=ironport2-out.teksavvy.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LAsXD-0005eT-F2 for emacs-devel@gnu.org; Thu, 11 Dec 2008 15:53:23 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkcFALcMQUlMConz/2dsb2JhbACBbM0LgnmBLA X-IronPort-AV: E=Sophos;i="4.36,206,1228107600"; d="scan'208";a="30940641" Original-Received: from 76-10-137-243.dsl.teksavvy.com (HELO pastel.home) ([76.10.137.243]) by ironport2-out.teksavvy.com with ESMTP; 11 Dec 2008 15:53:07 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id 5B6E186F6; Thu, 11 Dec 2008 15:53:07 -0500 (EST) In-Reply-To: <86tz9asgdv.fsf@lifelogs.com> (Ted Zlatanov's message of "Thu, 11 Dec 2008 12:42:20 -0600") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:106817 Archived-At: >>> Then any ELisp function that builds on atomics is atomic >>> itself, presumably (except for macros and other trickery). SM> No, atomicity does not work that way, sadly. > "atomic" was a bad word choice on my part. I meant "safe to put in an > (atomically) body as you described it." I think if functions A and B > are safe, then any function C that only uses A and B is safe too. Does > that make more sense? Yes, that makes sense. Hopefully, most functions are "safe" in this respect. BTW, implementing "atomically" is not necessarily that hard. Of course, it can be implemented with an "optimistic locking" discipline where we track changes and undo them if the transaction aborts, but until we get there, there are meny much simpler implementations which will be useful. A first implementation is (defmacro atomically (&rest body) `(let ((inhibit-thread-switch t)) ,@body)) A better one, yet still trivial, is (defconst the-lock (make-lock)) (defmacro atomically (&rest body) `(progn (lock-grab the-lock) (unwind-protect (progn ,@body) (lock-release the-lock)))) -- Stefan