/* * CS360: * Jim Plank * p4a.c */ #include #include void *printme(void *v) { int *i; i = (int *) v; printf("Hi. I'm thread %d\n", *i); pthread_exit(NULL); } main() { int i, vals[4]; pthread_t tids[4]; void *retval; for (i = 0; i < 4; i++) { vals[i] = i; pthread_create(tids+i, NULL, printme, (void *) (vals+i)); } for (i = 0; i < 4; i++) { printf("Trying to join with tid %d\n", i); pthread_join(tids[i], &retval); printf("Joined with tid %d\n", i); } pthread_exit(NULL); }