[chuck-users] time goes backwards (and I don't like that)

Robert Poor rdpoor at gmail.com
Fri Mar 13 19:35:40 EDT 2009


Kas:

I think you're right about two separate bugs (time goes backward,  
yield doesn't always yield), and I think this code makes it clearer:
==============pasted code below==============
Event e;
spork ~ costello();
abbot();

fun void abbot() {
     while (1) {
         now + 1.00001::second => time later;
         <<< "abbot(1):", now, later >>>;
         later => now;
         <<< "abbot(2):", now, later >>>;
         e.broadcast();
         <<< "abbot(3):", now, later >>>;
         me.yield();
         <<< "abbot(4):", now, later >>>;
     }
}

fun void costello() {
     while (1) {
         <<< "costello(1):", now >>>;
         e => now;
         <<< "costello(2):", now >>>;
     }
}
==============annotated output below==============
[poorbook15-8:~] r% chuck bar.ck
abbot(1): 0.000000 44100.441000 				// abbot about to block on later  
=> now
costello(1): 0.000000 							// costello gets a chance to run
abbot(2): 44100.441000 44100.441000 		// abbot unblocks, about to  
broadcast
abbot(3): 44100.441000 44100.441000 		// abbot has broadcast, about to  
yield()
costello(2): 44100.000000 					// abbot yielded, costello runs BUT NOW  
IS TRUNCATED
costello(1): 44100.000000 					// costello is about to block on e => now
abbot(4): 44100.441000 44100.441000 		// abbot has yielded, about to  
loop.
abbot(1): 44100.441000 88200.882000 		// abbot about to block on later  
=> now
abbot(2): 88200.882000 88200.882000 		// abbot unblocks, about to  
broadcast
abbot(3): 88200.882000 88200.882000 		// abbot has broadcast, about to  
yield
abbot(4): 88200.882000 88200.882000 		// abbot has yielded BUT  
COSTELLO DIDN'T RUN
abbot(1): 88200.882000 132301.323000 		// abbot about to block on  
later => now
costello(2): 88201.000000 					// costello runs, BUT NOW IS TRUNCATED
costello(1): 88201.000000 					// etc...
abbot(2): 132301.323000 132301.323000
abbot(3): 132301.323000 132301.323000 		// abbot has broadcast, about  
to yield
costello(2): 132301.000000 					// aha!  the yield worked!
costello(1): 132301.000000
abbot(4): 132301.323000 132301.323000
abbot(1): 132301.323000 176401.764000
===========================
Note that yield() seems to take effect sometimes and not others.  Ugh.

If anyone asks me to, I can write this as a more automated test to  
check for both errors.  Is there an official "test harness" for ChucK,  
i.e. using asserts() or the equivalent?

- Rob



More information about the chuck-users mailing list