[chuck-users] durations and control structures

Ge Wang gewang at CS.Princeton.EDU
Wed Apr 19 23:11:17 EDT 2006


> I suppose controlling shreds would involve and removing shreds around
> a central structure like this?

That's one possibility.  Another is to share data (or events) from 
multiple
shreds, and using those to synchronize things.

> Once I spork one shred, can I give it a name so that I can remove it
> with chuck code?

You can get a Shred reference back, and then refer to it by id:

// define function
fun void foo()
{
     while( true )
     {
         <<< "hi" >>>;
         .2::second => now;
     }
}

// spork the function, remember the shred reference
spork ~ foo() @=> Shred @ s;

// wait for 2 seconds
2::second => now;

// remove by id
machine.remove( s.id() );

// wait a little more
2::second => now;

Best,
Ge!



More information about the chuck-users mailing list