I'm trying to communicate between shreds. The docs say static data
isn't completely implemented so I realize this may not be possible
right now. If it is possible, I wondering if someone could let me
know if I'm taking the correct approach here and how I might achieve
this goal.
I run the command "chuck TheEvent.ck events.ck" and get this result:
[chuck](VM): sporking incoming shred: 3 (events2.ck)...
[chuck](VM): sporking incoming shred: 4 (events2.ck)...
[chuck](VM): sporking incoming shred: 5 (events2.ck)...
[chuck](VM): sporking incoming shred: 6 (events2.ck)...
"signaling" : (string)
"signaling" : (string)
"signaling" : (string)
"signaling" : (string)
...
It keeps signaling but the data is never printed. The three files
used are given below.
Thanks for any help,
Ollie
========================= TheEvent.ck =========================
public class TheEvent extends Event
{
static int value;
}
========================= events.ck =========================
// the event
TheEvent e;
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 ) => e.value;
// signal one waiting shred
e.signal();
<<<"signaling">>>;
}
========================= events2.ck =========================
// the event
TheEvent e;
// loop
while( true )
{
// wait on event
e => now;
// get the data
<<
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
<<
participants (2)
-
Ge Wang
-
Ollie Glaskovik