//hw 4 solving euclid's gcd alg with threads //Tracy Kapp #include #include #include #include #include #include #include #include #include void *worker(void *); void *holder(void *); pthread_mutex_t security; pthread_cond_t condition; unsigned count; int remaining; int N; int ready[10]; //to tell worker if work needs to be done on that index int pairs[10][2]; //to store pairs for each thread int temp_pairs[10][2]; //stores original pairs for output at end of computation main (int argc, char **argv) { pthread_t gcd[10], work; int i, index[N+1], ret; int j; count=0; N=argc/2; //sets N to num of threads needed remaining = N; if (argc < 3 || argc%2 != 1){ //tests for invalid input printf("not enough args\n"); exit(0); } for (i=0;i0){ int k, temp; pthread_mutex_lock(&security); //these lines cut and pasted from dec-inc program while(count==0) pthread_cond_wait(&condition, &security); count--; if (remaining<=0) exit(0); for (k=0;k