[chuck-users] Why do child shreds get killed?
Adam R. Tindale
adamtindale at hotmail.com
Tue Sep 6 19:55:11 EDT 2005
Hi Robin,
There is a solution to your problem. Instead of sporking a shred you
can use machine.add(). This will behave as if you added another file in
your argument.
In the following example it would be the same as typing chuck main.ck
loop.ck but all you have to do is chuck main.ck and the main shred
schedules loop.ck in the first line with machine.add().
Here is a main file with a function and a call to machine.add()
"loop.ck" => machine.add;
fun void foo(){
<<<"function">>>;
while(1::second => now)
<<<"I'm a function!">>>;
}
spork ~ foo();
Here is the content of loop.ck
while(1::second => now)
<<<"I'm a file!">>>;
As you pointed out, the function printing won't occur. This example
will keep chuck alive with the other shred. I also use chuck to make
songs in the fashion you described. I have a main patch that sporks
shreds that contain the instruments and I use control signals in the
main shred to change the song.
machine.add() returns an int so it is easy to remove sporked shreds
using machine.remove(). You can try something like this:
Event changesong;
"file.ck" => machine.add => int song1;
changesong => now;
song1 => machine.remove;
Happy ChucKing. I hope this helps until sporking becomes more powerful.
--art
More information about the chuck-users
mailing list