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: advice needed for multi-threading patch Date: Thu, 24 Sep 2009 13:25:03 -0400 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1253813128 10268 80.91.229.12 (24 Sep 2009 17:25:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 24 Sep 2009 17:25:28 +0000 (UTC) Cc: Emacs development discussions To: Tom Tromey Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Sep 24 19:25:21 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 1Mqs4H-0002a3-1Z for ged-emacs-devel@m.gmane.org; Thu, 24 Sep 2009 19:25:21 +0200 Original-Received: from localhost ([127.0.0.1]:53833 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mqs4G-0006Ot-Am for ged-emacs-devel@m.gmane.org; Thu, 24 Sep 2009 13:25:20 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mqs4A-0006OU-QI for emacs-devel@gnu.org; Thu, 24 Sep 2009 13:25:14 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mqs45-0006Ne-5d for emacs-devel@gnu.org; Thu, 24 Sep 2009 13:25:13 -0400 Original-Received: from [199.232.76.173] (port=55987 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mqs45-0006NZ-2S for emacs-devel@gnu.org; Thu, 24 Sep 2009 13:25:09 -0400 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:58919) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mqs44-0007pL-Oc for emacs-devel@gnu.org; Thu, 24 Sep 2009 13:25:08 -0400 Original-Received: from faina.iro.umontreal.ca (faina.iro.umontreal.ca [132.204.26.177]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id n8OHP36K003294; Thu, 24 Sep 2009 13:25:03 -0400 Original-Received: by faina.iro.umontreal.ca (Postfix, from userid 20848) id 0C1583A122; Thu, 24 Sep 2009 13:25:03 -0400 (EDT) In-Reply-To: (Tom Tromey's message of "Tue, 22 Sep 2009 21:16:07 -0600") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV3370=0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) 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:115585 Archived-At: > Yeah. What I meant here is that specbind has a little extra code in it > to install a Lisp_ThreadLocal object when needed. So, if the C code > uses specbind to do let-like binding, everything will work fine. If the > C code does not do this, then things will break. I see, yes of course it's a problem. And it's worse than that: the same holds for *all* global variables, whether they are exported to Lisp or not. Stefan> I think it should, unless some of the buffer-local variables are Stefan> let-bound by the thread. > I've been thinking about this a bit. It is trickier than it seems, > because a thread can actually have let-bindings for buffer-locals from > multiple buffers at the same time. There's an example of this in the > elisp manual. (This is also an area the threading code does not handle > well yet.) > I think this means it does not suffice to keep a simple per-thread count > of buffer-local bindings. Indeed. The lock should probably be on the buffer-local binding itself (i.e. the combination of the buffer and the variable). > While thinking about this I realized that (I think) the current code > does the wrong thing if one thread let-binds a variable and then another > thread calls make-variable-buffer-local on it. Calling make-variable-buffer-local or make-local-variable when the variable is let-bound is a serious problem, yes. IIRC we already have bugs in such cases in the current code. AFAICT, the only good answer is to disallow such things (e.g. signal an error in make-variable-buffer-local and make-local-variable when the var is let-bound). I already took a tiny step in that direction when I added a warning to defvar when called while the variable is let-bound. > It is hard for me to see how this could be done in a compatible way. Agreed. > Right now elisp operates with few constraints; an elisp program can call > select-frame, which seems to imply that per-frame or per-keyboard > threads can't be done. The way I think of it is that select-frame would send a message to the relevant frame, along with a function to run there, and the destination to which to send the result when the function is done. But how to link it with the dynamic and foo-local scoping of let-bindings is still far from clear. > One thing that would help me is having a concrete idea of what subset of > features would make this work be actually useful. I mostly implemented > it because it was cool, and because Giuseppe's initial patch convinced > me that it was possible (before that I'd written it off as totally > impractical). Now that a proof of concept works it would be nice to > have a concrete goal. Some goals could be: - run Gnus in its own thread. This should be easy-ish since Gnus shouldn't interact with pretty much anything else. - split Gnus into several threads (e.g. in my case, the most important one would be a thread to do the "g", i.e. refresh the *Group* buffer, which with IMAP boxes can takes ages). This is a lot more difficult since this thread would need to interact with the main Gnus thread. - move the jit-lock-context to a thread. Might be non-trivial, but at least the code is small. - move some VC operations to threads (e.g. vc-checkin). - run some of the buffer-parsing code in threads (e.g. the one in CEDET's semantic, or the one in js2-mode). Stefan