|
David Given kirjoitti 26.6.2008 kello 0:51:
[...]K= lanes.keeper() f(K) -- launches sublane, gives access to the keeper tableIs this actually true shared data between the two lanes? That is, either lane can read or write to it and the other one will see it? If so, cool--- but how did you make it work?
Yes, it's true shared data. And it's shared by 1..N lanes, anyone the creating lane has passed the pointer to it.
There is a pool of storage states, which carry the kept data (maybe I'll use them for FIFOs as well but that's an implementation issue). The lanes see the table as userdata, which essentially means only one level of indexing is usable:
K.a= 50 --ok K.b= { 50, 42, anything=9 } -- ok, written atomicallyK.b.anything= 5 -- NOT ok, will read K.b and set the local copy's .anything to 5 (and then forget it)
Keeper tables maybe cannot be waited upon, which makes the Linda you mentioned seem very lucrative. I was actually close to that idea myself, but didn't know what re-writing to an existing slot should do. Now I know. :)
-asko
...One thing nobody's mentioned is a third IPC mechanism which doesn't get a lot of press these days, called Linda. I think this is best describedas a pipe which is a table: t = tuple() --- access Linda tuplespace (traditionally, Linda only has one) Thread 1: t.foo = 1 -- writes value to tuplespace t.foo = 2 -- blocks until the slot is vacant, then writes Thread 2: print(t.foo) -- blocks until the slot is full, and consumes it, returning the value print(t.foo) -- blocks again There's also a primitive for polling a value without consuming it. I think this provides a rather richer IPC system than a simple messagepipe, allowing you to use the same tuplespace for implementing a varietyof different protocols simultaneously; also, the table-like semantics looks to me like it would fit Lua very nicely.