/*Marcus Daniels June 9, 1999 swarm-support >>>>> "XH" == xueyue writes: XH> So, the question here really is: can 'schedule' randomly schedule XH> events and excute them in their supposed order? Yes, that certainly should work. Can you frob this program to demonstrate the broken behavior you think exists? I can't reproduce what you describe. */ #import #import #import #import #define ITERATIONS 10000 #define MINSTEP 9 #define MAXSTEP 250 #define REGULARSTEP 15 @interface Controller: SwarmObject { unsigned count; id schedule; unsigned scheduled[ITERATIONS * MAXSTEP]; unsigned executed[ITERATIONS * MAXSTEP]; } - (void)schedule: (timeval_t)t; - reschedule; - start; @end @implementation Controller - (void)schedule: (timeval_t)t { scheduled[t]++; [schedule at: t createActionTo: self message: M(reschedule)]; } - reschedule { timeval_t now = getCurrentTime (); printf ("now: %lu", now); executed[now]++; if (count < ITERATIONS) { unsigned off = [uniformUnsRand getUnsignedWithMin: MINSTEP withMax: MAXSTEP]; timeval_t then1 = now + off; timeval_t then2 = now + REGULARSTEP; printf (" then1: %lu then2: %lu (%u)", then1, then2, off); [self schedule: then1]; [self schedule: then2]; count++; } putchar ('\n'); return self; } - start { count = 0; schedule = [Schedule create: globalZone]; [self schedule: 3]; [[schedule activateIn: nil] run]; return self; } - (void)check { timeval_t i; printf ("checking..\n"); for (i = 0; i < MAXSTEP * ITERATIONS; i++) if (executed[i] != scheduled[i]) printf ("mismatch on timestep %lu (schedule: %u executed: %u)\n", i, scheduled[i], executed[i]); } @end int main (int argc, const char **argv) { initSwarmBatch (argc, argv); [[[Controller create: globalZone] start] check]; return 0; } /* Local Variables: compile-command: "/opt/gnu/bin/gcc -o s2 -g -Wno-import -L/opt/SUNWtcl/8.0/sun4/lib -R/opt/SUNWtcl/8.0/sun4/lib -L/opt/SDGblt/2.4g/lib -R/opt/SDGblt/2.4g/lib -L/opt/SDGlibffi/1.20/lib -R/opt/SDGlibffi/1.20/lib -L/opt/SDGswarm/1.4.1/lib -L/opt/SDGzlib/1.1.3/lib -L/usr/local/X11/lib -R/usr/local/X11/lib -L/usr/openwin/lib -R/usr/openwin/lib -L/opt/SDGhdf5/1.0.1/lib -I/opt/SDGswarm/1.4.1/include s2.m -lanalysis -lsimtools -lsimtoolsgui -lactivity -ltkobjc -lrandom -lobjectbase -ldefobj -lcollections -lmisc -ltclobjc -ltk8.0 -ltcl8.0 -lBLT -lsocket -ldl -lnsl -L/usr/openwin/lib -lhdf5 -lpng -lz -lXpm -lX11 -lffi -lm -lobjc -lpthread -lposix4" End: */