[Top][All Lists]

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

multi-threaded Emacs

From: Giuseppe Scrivano
Subject: multi-threaded Emacs
Date: Sat, 29 Nov 2008 14:32:22 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)


I attached a small patch that enables basic threads in Emacs; it is just
a proof of concept and not usable yet, my goal was the execution of the
elisp code I included at the bottom.

In the new file thread.c these functions are defined:

(with-thread id '(code))
(kill-thread id)

The first one creates a suspended thread that is waiting for requests.
These requests are done by with-thread that allows the execution of
'(code) on the specified thread.  `kill-thread' is used to terminate a
thread execution by its id.

It is a prototype and the code is not very clean, still a lot of work
must be done in order to have working threads, but I think that have a
multi-threaded Emacs worths this effort.

My idea is to share global variables among threads while local bindings
are done locally to threads.

I haven't well investigated all problems that will raise using threads
in Emacs, the first one that come to my attention is the garbage
collector and at the moment I simply disable GC while there are running

The following elisp code can be used now, it is not safe as the new
thread id is not freed after it is used:

  (setq i 0)
  (setq j 0)
  (with-thread (create-thread) '(while (< i 20)
                                  (sleep-for 0.2)
                                  (print "hello")
                                  (setq i (1+ i))))
  (while (< j 20)
    (print "world")
    (sleep-for 0.25)
    (setq j (1+ j))))

`with-thread' allows to use the same thread multiple times like:

(with-thread foo '(do-something-complex))
(with-thread bar '(do-another-complex-thing))
(with-thread foo '(do-another-complex-thing))

The third call will block the calling thread until `foo' has completed
its previous execution.

What do you think about?


Attachment: emacs_multithread.diff.gz
Description: Binary data

reply via email to

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