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: advice needed for multi-threading patch Date: Mon, 28 Sep 2009 20:30:15 -0600 Message-ID: References: Reply-To: Tom Tromey NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1254191441 25342 80.91.229.12 (29 Sep 2009 02:30:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 29 Sep 2009 02:30:41 +0000 (UTC) Cc: Emacs development discussions To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Sep 29 04:30:34 2009 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 1MsSU4-0004Tz-My for ged-emacs-devel@m.gmane.org; Tue, 29 Sep 2009 04:30:33 +0200 Original-Received: from localhost ([127.0.0.1]:33830 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MsSU3-000291-VR for ged-emacs-devel@m.gmane.org; Mon, 28 Sep 2009 22:30:31 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MsSTy-00028m-4I for emacs-devel@gnu.org; Mon, 28 Sep 2009 22:30:26 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MsSTs-00028a-Mz for emacs-devel@gnu.org; Mon, 28 Sep 2009 22:30:24 -0400 Original-Received: from [199.232.76.173] (port=40519 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MsSTs-00028X-Hm for emacs-devel@gnu.org; Mon, 28 Sep 2009 22:30:20 -0400 Original-Received: from mx1.redhat.com ([209.132.183.28]:23583) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MsSTs-0006Va-1N for emacs-devel@gnu.org; Mon, 28 Sep 2009 22:30:20 -0400 Original-Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8T2UIYJ020768; Mon, 28 Sep 2009 22:30:18 -0400 Original-Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8T2UHm5016788; Mon, 28 Sep 2009 22:30:17 -0400 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 n8T2UFX3015087; Mon, 28 Sep 2009 22:30:16 -0400 Original-Received: by opsy.redhat.com (Postfix, from userid 500) id 96A6D37818C; Mon, 28 Sep 2009 20:30:15 -0600 (MDT) X-Attribution: Tom In-Reply-To: (Stefan Monnier's message of "Mon, 28 Sep 2009 20:27:14 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 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:115765 Archived-At: Stefan> So what should happen in the following case: Stefan> Thread A, running in buffer B1, runs the following code: Stefan> (let ((default-directory "/foo")) Stefan> (with-current-buffer B2 default-directory)) Stefan> You seem to say that it should return "/foo", but currently it returns Stefan> something else. I didn't mean to imply that. I've been too terse, I'll try to expand a bit more. First, I think it is clear that the case where there is just a single thread running should work exactly as elisp does today. So, the above will continue to work -- it has to for compatibility. To this end, I've written a bindings test suite that is on the branch. It is incomplete but it does test things like the above. I'm happy to add any tests you think appropriate to catch more possible problems. (This is also the one piece that could probably go into trunk immediately.) The way ordinary variables work on the branch is, in the base case, just like current elisp: the value is stored in Lisp_Symbol::value. Then, if a thread let-binds the variable, we create a struct Lisp_ThreadLocal. This has a slot for the global (un-shadowed) value, and also an alist of thread-local values, keyed by thread. There are 8 other kinds of variable bindings in Emacs: * defvaralias. These work exactly like ordinary bindings, they require no change. * objfwd. These work exactly as above, because we wrote that "semantic patch" to add #defines which indirect through the Lisp_ThreadLocal, when needed. * intfwd * boolfwd. These are not done yet. I think I will write another semantic patch to handle these, like we discussed earlier. Exactly what approach I'll use, I don't know... maybe make them exactly like objfwd and put a flag bit into Lisp_Objfwd, or keep the same structs and change the value's field type. * buffer-local * buffer-objfwd. Right now each of these has a single conceptual "value" field. (Where this is stored and how it is accessed is different in the two cases, but that doesn't matter.) What I propose to do is allow the same sort of thread-local indirection where this value is stored, so that a buffer-local will have a global value and then a separate per-thread value in each thread that has let-bound the variable. I wrote the big part of this patch already (adding accessors and updating all the C code), all that remains is fixing up symval forwarding and whatnot. * keyboard-local * frame-local I haven't looked into these yet, but I assume we'll end up wanting to do the same as buffer-locals. Stefan> A related case is when a process filter or a sentinel is run via Stefan> accept-process-output: we'd need to be careful to make sure the Stefan> code is run in the same thread as the code that called Stefan> accept-process-output. Yes, good point. Tom> There are some oddities implied by making buffer-local let-bindings Tom> also be thread-specific. For example, some buffer-locals affect Tom> redisplay, so what the user sees will depend on the thread in which Tom> redisplay is run. Stefan> Redisplay should be run in a completely separate thread (at least Stefan> conceptually). Yeah, that would be nice. I don't know much about redisplay, so I don't have much idea of how hard this would be, or what problems might arise. Tom