2009/4/21 Hans Aberg <haberg@math.su.se>
Is it possible to kill a thread by saving a reference and calling exit() (or something) on that reference? Are there any means by which a created thread can be manipulated from without it by its reference?

Like this?

fun void foo()
    {
    while(1)
        {
        <<<"beep">>>;
        second => now;
        }
    }

spork ~foo() @=> Shred bar;

3::second => now;

bar.exit();
second => now;
<<<"bye">>>;

Sadly there is currently a bug when we define a Shred object and later assign a actual shred to it; this will crash ChucK. This bug was likely caused by the last update which attempted to clean up the relationship between Shred objects and actual running processes (this wasn't always a very clear relationship).

You can also have the Shred report it's number using me.id() inside that shred and set Machine.remove(int id ) loose on that.

If this crashing bug bothers you (and it likely will) you can use this construct to get a shred's id number while sporking it;
<<<(spork ~foo()).id()>>>;

This integer can then be used with Machine.remove() to remove the shred.

There are more illustrations in /examples/shred/

I think that should get you out of trouble? I can't recommend the /examples/ directory highly enough as a resource.

Yours,
Kas.