Why doesn't this simple code display any messages? class MyEvent extends Event { string s; } // class MyEvent spork ~ f(); MyEvent e; e => now; // wait for it // this is never printed and this shred never exits <<<"Event occured.">>>; me.exit(); function void f() { MyEvent e; while (true) { // fire one event per second e.broadcast (); 1::second => now; } // while //<<<"Broadcast...">>>; } // f Thanx muchly as always. <smile> -- Rich
In you're example you're creating two separate events, one in the main
shred and one in the call to function f(). These events have the same
type, but they won't communicate because they are different events.
The way events work is that one or more shreds wait on the event, and
then another shred uses the event's signal() method to wake up the
first shred in the queue, or the broadcast() method to wake up all of
the shreds.
This slight modification to your code does work:
// BEGIN CODE
class MyEvent extends Event {
string s;
} // class MyEvent
MyEvent e;
spork ~ f(e);
e => now; // wait for it
// this is never printed and this shred never exits
<<<"Event occured.">>>;
me.exit();
function void f(MyEvent e) {
while (true) { // fire one event per second
e.broadcast ();
1::second => now;
} // while
//<<<"Broadcast...">>>;
} // f
// END CODE
I've created an event e before sporking on function f(), and f() now
takes an event as an argument. This way, the main shred and the
sporked shred communicate using the event e.
andy
On Tue, Nov 9, 2010 at 9:21 PM, Rich Caloggero
Why doesn't this simple code display any messages?
class MyEvent extends Event { string s; } // class MyEvent
spork ~ f();
MyEvent e; e => now; // wait for it // this is never printed and this shred never exits <<<"Event occured.">>>; me.exit();
function void f() { MyEvent e; while (true) { // fire one event per second e.broadcast (); 1::second => now; } // while
//<<<"Broadcast...">>>; } // f
Thanx muchly as always. <smile> -- Rich
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
Andy, thank you for your help; this is great!
I've created an event e before sporking on function f(), and f() now takes an event as an argument. This way, the main shred and the sporked shred communicate using the event e.
Does this mean that all the code for the shreds must reside in the same
file?
I've read that you can use public classes from other files, so I assume you
can pass event objects around like that way?
Thanks again...
-- Rich
----- Original Message -----
From: "Andrew Turley"
In you're example you're creating two separate events, one in the main shred and one in the call to function f(). These events have the same type, but they won't communicate because they are different events. The way events work is that one or more shreds wait on the event, and then another shred uses the event's signal() method to wake up the first shred in the queue, or the broadcast() method to wake up all of the shreds.
This slight modification to your code does work:
// BEGIN CODE class MyEvent extends Event { string s; } // class MyEvent
MyEvent e;
spork ~ f(e);
e => now; // wait for it // this is never printed and this shred never exits <<<"Event occured.">>>; me.exit();
function void f(MyEvent e) { while (true) { // fire one event per second e.broadcast (); 1::second => now; } // while
//<<<"Broadcast...">>>; } // f // END CODE
I've created an event e before sporking on function f(), and f() now takes an event as an argument. This way, the main shred and the sporked shred communicate using the event e.
andy
On Tue, Nov 9, 2010 at 9:21 PM, Rich Caloggero
wrote: Why doesn't this simple code display any messages?
class MyEvent extends Event { string s; } // class MyEvent
spork ~ f();
MyEvent e; e => now; // wait for it // this is never printed and this shred never exits <<<"Event occured.">>>; me.exit();
function void f() { MyEvent e; while (true) { // fire one event per second e.broadcast (); 1::second => now; } // while
//<<<"Broadcast...">>>; } // f
Thanx muchly as always. <smile> -- Rich
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
participants (2)
-
Andrew Turley
-
Rich Caloggero