#include #include #include #define NUM_THREADS 10 // Exercise 2 variables pthread_mutex_t counter_lock = PTHREAD_MUTEX_INITIALIZER; int global_counter = 0; // Exercise 3 variables pthread_mutex_t print_order_lock = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t evens_done_CV = PTHREAD_COND_INITIALIZER; int number_evens_finished = 0; void *sayHello(void *temp_id) { int i; int global_counter_copy; int id = (long) temp_id; // store a casted version to avoid some compiler warnings printf("Hello! I am thread id %d!\n",id); for(i=0; i < 1000000; i++) { } global_counter_copy = global_counter; printf("Bye! I am thread id %d and I was #%d to print!\n",id,global_counter_copy); for(i=0; i < 1000000; i++) { } global_counter = global_counter_copy+1; pthread_exit(NULL); } int main(void) { int ii; pthread_t threads[NUM_THREADS]; printf("Hello, I am the main thread just starting\n"); // create threads for(ii = 0; ii < NUM_THREADS; ii++) { // for the first part of Exercise 1 // YOUR FIRST LINE OF CODE HERE } // for the second part of Exercise 1 // JOIN THREADS HERE printf("Main thread saying goodbye!\n"); }