[chuck-users] Inter-shred communication

Ge Wang gewang at CS.Princeton.EDU
Mon Nov 28 17:56:58 EST 2005


Hi Ollie,

All is good except that you probably want to make a static TheEvent 
somewhere and use that one instance among the shreds.  slightly modified 
code below, with a new class 'The' to hold the global/static object(s).

to run:

     > chuck TheEvent The events

========================= TheEvent.ck =========================

  public class TheEvent extends Event
  {
      int value;
  }

========================= The.ck ==============================

  public class The
  {
      // declare static reference to TheEvent
      // (due to 'static' not fully implemented for objects)
      static TheEvent @ e;
  }

  // instantiate out here
  // (due to 'static' not fully implemented for objects)
  new TheEvent @=> The.e;

========================= events.ck =========================

  machine.add( "events2.ck" );
  machine.add( "events2.ck" );
  machine.add( "events2.ck" );
  machine.add( "events2.ck" );

  // infinite time loop
  while( true )
  {
     // advance time
     1::second => now;

     // set data
     math.rand2( 0, 5 ) => The.e.value;

     // signal one waiting shred
     The.e.signal();

     <<<"signaling">>>;
  }

========================= events2.ck =========================

  // loop
  while( true )
  {
     // wait on event
     The.e => now;

     // get the data
     <<<me.id(), The.e.value>>>;
  }

==============================================================

Hope this helps!

Best,
Ge!


More information about the chuck-users mailing list