[chuck-users] Events as shared instance variables across shreds

David Michael david.michael at gmail.com
Mon Jan 29 21:53:03 EST 2007


Bear (bare?) with me,

Is it advisable to have Events as instance variables so that shreds  
sporked from that instance all reference this internal event?

The code below works in practice.
(I have not run the code example, but I do something similar in a  
program).

Are there any pitfalls to doing this, rather than explicitly passing  
in the Event, as is shown in the language tutorials?

Many thanks in advance,
D


// event as instance variable across shreds
// -----------------------------------------------------------

class Object
{
   new Event @=> Event event;

   function first()
   {
     while(true)
     {
       this.event.signal();
       1::second => now;
     }
   }

   function second()
   {
     while(true)
     {
       this.event => now;
       <<< "recieved event" >>>;
     }
   }
}

Object object;

spork ~ object.first();
spork ~ object.second();


More information about the chuck-users mailing list