From: Juan Jose Garcia-Ripoll
Subject: Multithreaded ECL
Date: 
Message-ID: <bpsouj$1stpu9$1@ID-212141.news.uni-berlin.de>
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
        http://ecls.sf.net/patch-current-mp.gz
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, 
INTERRUPT-PROCESS, PROCESS-NAME, ALL-PROCESSES, MAKE-LOCK, GET-LOCK, 
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 
nuts.

* 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 
investigated).

* Packages are safe in many ways. Two 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 (means only ugly output) if someone else
is writing to the same stream

* 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.

Regards,

Juanjo
From: John Stoneham
Subject: Re: Multithreaded ECL
Date: 
Message-ID: <RpOxb.374$l65.362504362@newssvr11.news.prodigy.com>
This stuff sounds great! I'll be happy to test what I can.

Keep up the good work, Juanjo!