-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 20-Feb-07, at 10:48 AM, Guillaume Germain wrote:
On 2/20/07, Lang Martin lang-gb@coptix.com wrote: I have a (possibly irrational) bias against mutexes, and attempted to solve a threading problem with just message passing. The code works, but only part of the time.
I haven't run your code myself, but I think I see a few things wrong with it.
Guillaume's analysis is correct. Let me add that perhaps you wanted this:
(define (foo) (let ((result (let ((th (thread-start! (make-thread (lambda () (let loop () (let ((p (thread-receive))) (thread-start! (make-thread (lambda () (p 40))))) (loop))))))) (+ 2 (call/cc (lambda (ret) (thread-send th ret) (thread-send th ret) (thread-send th ret) 111)))))) ;; all threads (except "th") will execute this: (pp result) (thread-sleep! 2)))
(foo)
This code creates the "server" thread "th" to receive continuations. For each continuation received, "th" will create a new thread which resumes this continuation. So "th" can be used as a server for cloning threads.
Marc