Okay, I'm having a bit of an "ah-ha!" moment here. It makes sense to
me when described like this. If I understand this process correctly,
data-sharing aside, this is functionally equivalent to using the
"chuck --loop" invocation to start the VM and sporking shreds with
"chuck + this.ck" and "chuck + that.ck." Or is that more like
Machine.add()?
According the manual, sporking a shred will return a reference to the
shred, while using Machine.add() will return the ID. Can one pass
messages between shreds in the VM like in Erlang processes using this
information? Using a shared variables to store state information
might get kind of hairy in big programs.
Mike
On 8/3/07, Kassen
I wish I had some examples of sporked shreds sharing data with each other, for instance.
Ok. Let's not go into sharing data between shreds that come from different .ck files just now as that's slightly advanced (but not that hard either).
For shreds that come from the same file, (this comes down to paralel sporked functions) there are a few things to keep in mind. Anything that gets defined inside of a function's definition {between the brackets} is that function's data and is seperate from there rest. However; anything that gets defined in the main text is shared by everything in that file. This includes ugen parameters. I'll demonstrate this now. In the code below we'll define a variable that is shared between paralel shreds and we'll have one shred writing to it and have the other shred print it. ========================= int shared;
fun void writer() { //let's just define another variable int example;
while(true) { Std.rand2(0, 10) => shared; second => now; } }
fun void reader() { //notice how this "example" won't clash with the other one //as each function has it's own namespace. //if you'd like to share data it would be a mistake to also //define a second int named "shared" here as that would confuse things. int example;
while(true) { <<<shared>>>; second => now; } }
spork ~ writer(); spork ~ reader();
while(true) { <<<"hello, I'm the main shred, I'm still alive!">>>; 5::second => now; } ==========================
This would be the most basic way to share data between shreds. I'd be happy to give more advanced examples if that's nesicary but in that case I'd have to know what direction you want to move in.
Also; I'm dyslexic and didn't test this code, just warning you :¬)
Yours, Kas.
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users