[Ecls-list] Multithreaded ECL

Juan Jose Garcia-Ripoll worm at arrakis.es
Mon Nov 24 03:06:07 UTC 2003

Does anybody want to contribute to the multithreaded ECL project? Testers are 
most welcome. I will regularly post big patch files (about 200k right now) at
which can be applied to the latest and very buggy release (ecl-0.9c.tar.gz), 
but anonymous access to CVS is another option (with one day delay).

Currently, the features are:

* Multiprocessing via POSIX threads (currently available only under Linux).

* In the "MP" package you will find PROCESS-RUN-FUNCTION, PROCESS-KILL, 
GIVEUP-LOCK, WITH-LOCK, WITHOUT-INTERRUPTS. Currently, lisp threads should 
only be handled by ECL. ECL should not be invoked from threads which have not 
been created by lisp (This will be solved in a near future).

* Dynamic bindings are inherited by children threads. For instance,
	(let ((*a* 2))
	  (declare (special *a*))
	  (mp:process-run-function #'(lambda () (loop (sleep 1) (print *a*))))
here the value of *a* becomes the global value of *a* in the new thread. If 
you do not use this, but
	(defvar *a* 2)
	(mp:process-run-function #'(lambda () (loop (sleep 1) (print *a*)))
then the value of *a* is common to both threads and one thread can change what 
the other sees. Otherwise you will have to use this funny trick:
	(defvar *a* "HOLA")
	(let ((x (mp::process-run-function "TEST"
			   #'(lambda () (loop (sleep 1) (print *a*))))))
	  (sleep 10)
	  (mp::interrupt-process x #'(lambda () (setf *a* "ADIOS")))
	  (sleep 10)
	  (mp::process-kill x))

* Hash tables can be made thread safe by adding a keyword parameter ":lockable 
t" to MAKE-HASH-TABLE. Otherwise, they can be corrupted and things may go 

* Arrays, structures and instances are not thread safe. Hmm, I should rather 
say that "growing" them (or structural operations in general) are not safe in 
these objects. Creating or modifying CLOS classes is also not thread safe, 
and there might be speed issues in the use of methods (this has to be 

* Packages are safe in many ways. Both threads may add and remove symbols from 
packages, and delete and create packages. Also streams should be safe (but 
the pretty printer may get confused if someone else is writing to the same 

* Loading and compiling files is protected with a global lock.

* Interrupts are the weakest point also in single-threaded ECL. I still have 
to figure out how to support interrupts without breaking in the middle of 
critical code. I also do not like the idea of executing interrupts 
synchronously, but it is difficult to add checks for pending interrupts 
throughout ECL. Maybe to defer signals, using alarm(), would be the wisest 



More information about the ecl-devel mailing list