/* * "equivalent" C code to the provided sample MIPS assembly driver * (MIPS has no printf etc, so equivalence inexact). */ void tmain(void *arg) { int thread_id = (int) arg; int i = 0; for (i = 0; i < 10; i++) { printf("Thread %d: %d\n",thread_id,i); thr_yield(); } } void foo(int who, int num) { printf("I am thread %d, and this is %d times through\n",who,num); thr_yield(); } void t2main(void *arg) { int thread_id = (int) arg; int i; for (i = 0; i < 10; i++) { foo(thread_id,i); printf("[ %d:%d ]\n",thread_id,i); thr_yield(); } } void main(void) { struct thr_state t0, t1, t2; int t0stk[512], t1stk[512], t2stk[512]; thr_init(&t0,tmain,0,t0stk,sizeof t1stk); thr_init(&t1,tmain,1,t1stk,4 * 512); /* equiv */ thr_init(&t2,t2main,2,t2stk,2048); thr_go(); printf("All done!\n"); }