[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multi-threaded Emacs

From: Giuseppe Scrivano
Subject: Re: multi-threaded Emacs
Date: Sun, 07 Dec 2008 00:41:02 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Stefan Monnier <address@hidden> 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))
#<thread 1>

  (run-in-thread a-thread '(dotimes (i 2)
                         (print "hello")

    (dotimes (i 2)
      (print "world")






reply via email to

[Prev in Thread] Current Thread [Next in Thread]