/* * ISA 563, Spring 2011 * Copyleft by Muhammad Abdulla */ #include #include #include /* * thread_arg_passing.c -- demonstrates how to pass parameters to thread functions */ #define MAX 7 #define MAXTH 5 void *print_id(void *tid) { int i; int id; id = (int) tid; for ( i = 0; i < MAX; i++ ) { printf("My id is: %d\n", id); } pthread_exit(NULL); } int main(int argc, char *argv[]) { pthread_t threads[MAXTH]; int rc; int i; for( i = 0; i < MAXTH; i++) { rc = pthread_create(&threads[i], NULL, print_id, (void *)i); if (rc) { printf("ERROR; return code from pthread_create() is %d\n", rc); exit(-1); } } pthread_exit(NULL); }