/* * CS460: Operating Systems * Jim Plank * print4.c -- forks off four threads that print their ids */ #include #include #include #include #include printme(i) int i; { printf("Hi. I'm thread %d\n", i); } main() { stkalign_t *stack[4]; int i; thread_t tids[4]; lwp_setstkcache(MINSTACKSZ*sizeof(stkalign_t), 4); for (i = 0; i < 4; i++) { stack[i] = lwp_newstk(); lwp_create(tids+i, printme, 1, 0, stack[i], 1, i); } for (i = 0; i < 4; i++) { printf("Trying to join with tid %d\n", i); lwp_join(tids[i]); printf("Joined with tid %d\n", i); } }