/* * CS460: Operating Systems * Jim Plank * sleeptest.c -- Testing out pt_sleep() */ #include #include "pt.h" long t0; typedef struct tst { int i; int tnum; } Tst; thread(t) Tst *t; { int j; j = random()%5; printf("%4d: Thread %d. i = %d. Sleeping for %d seconds\n", time(0)-t0, t->tnum, t->i, j); t->i++; pt_sleep(j, thread, t); } extern exit(); main() { int i; Tst *t; srandom(40); t0 = time(0); for (i = 0; i < 5; i++) { t = (Tst *) malloc (sizeof(Tst)); t->tnum = i; t->i = 0; pt_fork(thread, t); } pt_joinall(exit, 0); }