From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tom Tromey Newsgroups: gmane.emacs.devel Subject: Re: Patch for fields of `struct buffer' Date: Sun, 06 Feb 2011 19:44:15 -0700 Message-ID: References: <4D46E75E.7080503@harpegolden.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1297046672 1129 80.91.229.12 (7 Feb 2011 02:44:32 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 7 Feb 2011 02:44:32 +0000 (UTC) Cc: emacs-devel@gnu.org, David De La Harpe Golden To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Feb 07 03:44:26 2011 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.69) (envelope-from ) id 1PmH5W-0004Mx-Aj for ged-emacs-devel@m.gmane.org; Mon, 07 Feb 2011 03:44:26 +0100 Original-Received: from localhost ([127.0.0.1]:48720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PmH5V-0007Cd-Pb for ged-emacs-devel@m.gmane.org; Sun, 06 Feb 2011 21:44:25 -0500 Original-Received: from [140.186.70.92] (port=53287 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PmH5R-0007CN-6X for emacs-devel@gnu.org; Sun, 06 Feb 2011 21:44:22 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PmH5P-0000Mt-RN for emacs-devel@gnu.org; Sun, 06 Feb 2011 21:44:21 -0500 Original-Received: from mx1.redhat.com ([209.132.183.28]:24741) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PmH5P-0000Mp-I0 for emacs-devel@gnu.org; Sun, 06 Feb 2011 21:44:19 -0500 Original-Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p172iHDA018783 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 6 Feb 2011 21:44:18 -0500 Original-Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p172iHOJ016445; Sun, 6 Feb 2011 21:44:17 -0500 Original-Received: from opsy.redhat.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p172iGB0010531; Sun, 6 Feb 2011 21:44:16 -0500 Original-Received: by opsy.redhat.com (Postfix, from userid 500) id CEDF0378307; Sun, 6 Feb 2011 19:44:15 -0700 (MST) X-Attribution: Tom In-Reply-To: (Stefan Monnier's message of "Tue, 01 Feb 2011 10:43:09 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 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:135665 Archived-At: >>>>> "Stefan" == Stefan Monnier writes: Stefan> Erlang-style concurrency is nice and clean, but I'm not sure it'll Stefan> integrate well with existing code which stomps over a global state all Stefan> the time. This doesn't mean it won't work. If we can make it work Stefan> something like "one agent per buffer" and turn `set-buffer' into a kind Stefan> of message maybe we could get some good results, but it seems tricky. I couldn't think of a way to make this work, at least not with `set-buffer' as the primitive. I think it could be done by having all other buffer-manipulating primitives (e.g., `insert') work by message-passing to some other thread. This is basically like a buffer lock. Stefan> Threads and locks don't look too good: too low-level. If we go Stefan> in that direction, then STM seems a lot more appealing. I read up on STM and then spent some time thinking about it this weekend. I don't see how it could be implemented in Emacs without extreme hairiness in the C code. My thinking is along the lines of: a transaction could conceivably touch any lisp object, including buffer contents (I was thinking along the lines of: each call-interactively is a transaction automatically). So, any change anywhere would have to be logged and then potentially rolled back if a transaction is aborted. In particular, all heap modifications in the C code would need to be intercepted... orders of magnitude uglier than my proposed `struct buffer' patch. (Though FWIW I have thought about this particular change for other reasons -- you could introduce a software write barrier for the GC this way :-) Also I think heap reads would need to be intercepted and indirected to make transactions not prematurely affect other threads. So, this is quite hard and inefficient. I am interested in reasoned arguments, grounded in real Emacs code, to the contrary for either STM or CSP. Otherwise, sucky as it is, I think the approach will be explicit locking. I know I can make that one work ok, or "ok enough". After thinking about the Bordeaux threads model a bit more, I have come to the conclusion that I would prefer something simpler. E.g., if we went "Java style" and only provided `with-lock-held' (and not separate lock- and unlock- primitives), then we could eliminate a class of bugs. Likewise, I think (and I know we already disagree here) that only having recursive locks similarly eliminates a source of bugs. I think these issues are important because such bugs will show up to Emacs users in a particular un-fun way. Tom