|
Wednesday, March 24, 2004 |
Patrick Logan is writing about
a Kali-like mechanism for Stackless Python. Mention is made of being
able to migrate tasks to a different machine where they can be unpacked
and resumed.
I've updated my previous Sisc Scheme example of sending continuations to another machine to include migrating tasks. The 'ping-pong' example looks like:
(define (ping-pong)
(let loop ()
(display "ping\n")
(sleep 1000)
(migrate-thread "127.0.0.1" 9002)
(display "pong\n")
(sleep 1000)
(migrate-thread "127.0.0.1" 9003)
(loop)))
This starts on one machine, displays 'ping', migrates the thread to
another machine, writes 'pong' then goes back to the original machine
and continues forever. This can be started on a machine with:
(spawn-thread-on "127.0.0.1" 9003 ping-pong)
You can download the code from file remote-send.scm. This updated code also includes optionally compressing the continuation as it is serialized (turned on by default).
What 'migrate-thread' does is capture a continuation and sends that
continuation over to the other machine where is is restarted. The
running thread on the original machine is then terminated:
(define (migrate-thread host port)
(call/cc
(lambda (k)
(send host port k)
((exit-function)))))
10:26:59 AM
|
|
© Copyright 2005 Chris Double.
|
|
|