[chuck-users] time goes backwards (and I don't like that)
Robert Poor
rdpoor at gmail.com
Sat Mar 14 01:49:45 EDT 2009
Okay: have built a fresh 1.2.1.2 AND a fresh 1.2.1.1 and observe the
same error in both versions. Here's a revised test program that
nicely demonstrates that the problem lies with rounding: if the
fractional part of now between 0.0 and 0.5 (inclusive), it rounds
down. If it is greater than 0.5, it rounds up. And when the time is
rounded up, it appears that yield() doesn't yield.
==============pasted code below==============
Event e;
spork ~ costello();
abbot();
fun void abbot() {
while (1) {
now + 44100.25::samp => 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 >>>;
}
}
==============pasted output below==============
[poorbook15-8:Chuck/chuck-1.2.1.1-dev/src] r% ./chuck --version
chuck version: 1.2.1.1b (dracula)
exe target: mac os x : powerpc
http://chuck.cs.princeton.edu/
[poorbook15-8:Chuck/chuck-1.2.1.1-dev/src] r% ./chuck ~/bar.ck
abbot(1): 0.000000 44100.250000
costello(1): 0.000000
abbot(2): 44100.250000 44100.250000
abbot(3): 44100.250000 44100.250000
costello(2): 44100.000000 // 0.25 rounded down
costello(1): 44100.000000
abbot(4): 44100.250000 44100.250000
abbot(1): 44100.250000 88200.500000
abbot(2): 88200.500000 88200.500000
abbot(3): 88200.500000 88200.500000
costello(2): 88200.000000 // 0.5 rounded down
costello(1): 88200.000000
abbot(4): 88200.500000 88200.500000
abbot(1): 88200.500000 132300.750000
abbot(2): 132300.750000 132300.750000
abbot(3): 132300.750000 132300.750000
abbot(4): 132300.750000 132300.750000
abbot(1): 132300.750000 176401.000000
costello(2): 132301.000000 // 0.75 rounded up, failed to yield
costello(1): 132301.000000
abbot(2): 176401.000000 176401.000000
abbot(3): 176401.000000 176401.000000
costello(2): 176401.000000 // 0.0 behaves
costello(1): 176401.000000
abbot(4): 176401.000000 176401.000000
abbot(1): 176401.000000 220501.250000
abbot(2): 220501.250000 220501.250000
abbot(3): 220501.250000 220501.250000
costello(2): 220501.000000
costello(1): 220501.000000
abbot(4): 220501.250000 220501.250000
abbot(1): 220501.250000 264601.500000
abbot(2): 264601.500000 264601.500000
abbot(3): 264601.500000 264601.500000
costello(2): 264601.000000
costello(1): 264601.000000
abbot(4): 264601.500000 264601.500000
abbot(1): 264601.500000 308701.750000
C-c C-c[chuck]: cleaning up...
More information about the chuck-users
mailing list