[Stackless] More CSP

[NOTE: My email was dead for most of today - this is already out of
date.
Python implementation of alt *seems* to be working - will follow]
Hi All,
Having started to dig around, I'm coming to the conclusion that I may
start with an all-python solution that uses the existing channel support
and various scheduling hooks.
For example, par is very easy:
(For the uninitiated, A par construct runs a bunch of processes in
parallel, the par process itself terminates when all of the
sub-processes have terminated).
--------------------------
def par(*funcs):
taskEnd = channel()
def signalEnd(f):
f()
taskEnd.send(1)
for f in funcs:
tasklet(signalEnd)(f).run()
count = len(funcs)
while count > 0:
taskEnd.receive()
count -= 1
#Example usage:
def counter(c, out):
for x in range(1, c+1):
out.send(x)
out.send('end')
def accumulate(inp):
acc = 0
while 1:
x = inp.receive()
if x == 'end': break
acc += x
print acc
def test():
c = channel()
par(
lambda: counter(6, c),
lambda: accumulate(c)
)
-----------------------
Comments:
I'm assuming it's ok to send on a channel from multiple tasklets?? In
occam this is a 'shared' channel, in JCSP an 'any-to-one' channel.
The use of a channel to signal tasklet-end is perhaps a bit heavy? Are
chan.send() and chan.receive() the only ways to make the *current*
tasklet block?
Implementing alt entirely in python would probably get much more messy.
In particular, it might require a new altChannel class, that looks like
a channel (i.e. send/receive methods) but actually encapsulates more
than one 'real' channel, or multiple underlying sends/receives per
communication. This might be interesting as a proof of concept, but is
not a long term solution.
Tom.
_______________________________________________
Stackless mailing list
Stackless at stackless.comhttp://www.stackless.com/mailman/listinfo/stackless