/* * "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; static int tmain_spawn_stk[5][512]; static struct thr_state tmain_spawn_states[5]; for (i = 0; i < 5; i++) { thr_init(&tmain_spawn_states[i], t2main, 10 * thread_id + i, tmain_spawk_stk[i], 2048); } 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,t2main,1,t1stk,4 * 512); /* equiv */ thr_init(&t2,t2main,2,t2stk,2048); thr_set_pri(&t0,2); thr_set_pri(&t1,2); thr_set_pri(&t2,1); thr_go(); printf("All done!\n"); }