/* Try number 1 using pthreads * isn't guranteed to work - race condition on count * compile with: * * gcc count3s_parallel1.c -o count3s_parallel1 -pthread * * */ #include #include #include int num_threads = 1; // array to search - contains 9 threes int arr_length = 32; int arr[] = {2,3,0,2,3,3,1,0,0,1,3,2,2,3,1,0, 1,0,0,2,0,3,1,0,3,1,0,2,3,3,1,0}; // total of all threes found (won't necessarily work - race condition) int count=0; // args - long id void count3s_thread(void *id) { int i; // compute the portion of the array that this thread should // work on int length_per_thread = arr_length / num_threads; int start = (long)id * length_per_thread; //printf("Start from thread %d: %d\n", (long)id, start); for(i=start;i