[chuck-users] Killing thread from without

Kassen signal.automatique at gmail.com
Tue Apr 21 15:32:16 EDT 2009


2009/4/21 Hans Aberg <haberg at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20090421/93fbe8a3/attachment.htm>


More information about the chuck-users mailing list