/* * A test program that "simulates" the powers of 2, 3, and 5 up to * exponent 5. For testing. * * Based on code written by Gary Lindstrom. */ #include #include #include "scheduler.h" struct powers { struct process super; long base; }; static void powers_body(struct process *p) { struct powers *self = (struct powers *)p; struct scheduler *sched = p->scheduler; int next_time = self->base; for (int i = 1; i <= 5; i++) { sched_hold(sched, next_time - sched->clock); printf("%ld ^ %d = %d.\n", self->base, i, sched->clock); next_time = sched->clock * self->base; } } static struct process * powers_create(struct scheduler *sched, const char *n, int base) { struct powers *powers = calloc(1, sizeof(*powers)); powers->base = base; process_init(&powers->super, n, sched, powers_body); return &powers->super; } int main() { struct scheduler *sched = sched_create(); sched_activate_now(sched, powers_create(sched, "2-powers", 2)); sched_activate_now(sched, powers_create(sched, "3-powers", 3)); sched_activate_now(sched, powers_create(sched, "5-powers", 5)); // sched_print_ev_list(sched); sched_run_simulation(sched); }