[chuck-users] can there be many ::ms in while?

Kassen signal.automatique at gmail.com
Fri Aug 3 13:31:07 EDT 2007

> 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;

    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;

    second => now;

spork ~ writer();
spork ~ reader();

    <<<"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 :¬)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20070803/3eef7233/attachment.htm 

More information about the chuck-users mailing list