[chuck-users] Killing thread from without
Hans Aberg
haberg at math.su.se
Tue Apr 21 16:12:19 EDT 2009
On 21 Apr 2009, at 21:32, Kassen wrote:
> Like this?
>
> fun void foo()
> {
> while(1)
> {
> <<<"beep">>>;
> second => now;
> }
> }
>
> spork ~foo() @=> Shred bar;
>
> 3::second => now;
>
> bar.exit();
> second => now;
> <<<"bye">>>;
I think that tried that one, and it didn't work. Possibly because it
gets stuck in <delay> => now; - your example allows jumping out of it
in the 'while-loop.
> 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).
I didn't try that one (I think) - I used references @=>, both in an
array, and as a single global variable. exit() on such a reference
while the thread was stuck in '<delay> => now' didn't work.
> 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.
So this is perhaps what I should try, though using exit() on the thread.
> 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.
I grepped 'exit()' on the whole examples directory, but all finds were
'my.exit()', so it did not seem to apply.
Hans
More information about the chuck-users
mailing list