From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Giuseppe Scrivano Newsgroups: gmane.emacs.devel Subject: Re: multi-threaded Emacs Date: Sun, 07 Dec 2008 00:41:02 +0100 Message-ID: <87d4g4c1o1.fsf@master.homenet> References: <87abbiody1.fsf@master.homenet> <877i6l5d8s.fsf@master.homenet> <874p1npvtj.fsf@master.homenet> <87ej0qci8g.fsf@master.homenet> <87y6yxm7xr.fsf@master.homenet> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1228606890 24988 80.91.229.12 (6 Dec 2008 23:41:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 6 Dec 2008 23:41:30 +0000 (UTC) Cc: rms@gnu.org, emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Dec 07 00:42:33 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 1L96n9-0004SX-Nu for ged-emacs-devel@m.gmane.org; Sun, 07 Dec 2008 00:42:31 +0100 Original-Received: from localhost ([127.0.0.1]:60440 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L96lz-00040R-1o for ged-emacs-devel@m.gmane.org; Sat, 06 Dec 2008 18:41:19 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L96lv-00040C-3Q for emacs-devel@gnu.org; Sat, 06 Dec 2008 18:41:15 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L96lt-0003zt-IU for emacs-devel@gnu.org; Sat, 06 Dec 2008 18:41:14 -0500 Original-Received: from [199.232.76.173] (port=60023 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L96lt-0003zq-G0 for emacs-devel@gnu.org; Sat, 06 Dec 2008 18:41:13 -0500 Original-Received: from joe.mail.tiscali.it ([213.205.33.54]:36247) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1L96lr-0007aN-1z; Sat, 06 Dec 2008 18:41:11 -0500 Original-Received: from master.homenet (84.222.166.119) by joe.mail.tiscali.it (8.0.022) id 48F74907029C871D; Sun, 7 Dec 2008 00:41:08 +0100 Original-Received: from gscrivano by master.homenet with local (Exim 4.69) (envelope-from ) id 1L96li-0005WD-5z; Sun, 07 Dec 2008 00:41:02 +0100 In-Reply-To: (Stefan Monnier's message of "Sat, 06 Dec 2008 17:41:20 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) 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:106639 Archived-At: Stefan Monnier writes: >> It will be safe in the sense that it won't cause a crash. But it will >> mess up Elisp's semantics. Consider: > >> (dotimes (i 1000) (toto)) > >> if you run this code twice in separate threads and allow context >> switches at QUIT, then you'll basically be doing "preemptive >> concurrency" seen from Elisp's point of view. Among other things, the >> two threads will be fighting over the value of `i'. > >> Each thread should have its own local bindings. To do this >> requires swapping bindings in and out of the specpdls >> when switching threads. It is not hard. > >> This makes thread switches slower, and that makes it desirable >> to do them less often. > > It might be an acceptable temporary solution, but in the long term we > will want to allow true parallelism, so such trickery will not be > an option. Actually I am using what Richard suggested. Every thread has a specpdl and on a thread switch I copy the current symbol value inside its specbinding cell. Still there is much to do but now I am able to do this: (setq a-thread (make-thread)) # (progn (run-in-thread a-thread '(dotimes (i 2) (print "hello") (yield))) (dotimes (i 2) (print "world") (yield))) "hello" "world" "hello" "world" Giuseppe