[gambit-list] call/cc across threads
Marc Feeley
feeley at iro.umontreal.ca
Tue Feb 20 11:54:49 EST 2007
-----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 at 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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)
iD8DBQFF2yfa//V9Zc2T/v4RAsQzAKCE9dXTWW4OVqGQ5Md8tzyHaqeZ7ACeM4Y0
4+OBiOZ0JgYt5ux5mjRDmzg=
=mLJH
-----END PGP SIGNATURE-----
More information about the Gambit-list
mailing list