Question 11
The following program declares a global integer array called x with 1000 elements. It then launches two threads to sum the elements of the array in parallel. The first thread adds the first 500 elements of x and the second thread adds the second 500elements of the array. After they return, the main function adds the results returned from both threads and prints out the result. Please specify what goes into the blanks numbered [1] through [8].
int x[1000];
typedef struct {
int *array;
int size;
} arg_t;
void *sum_array(void *a) {
arg_t *arg = a;
int *sum = __[1]__;
*sum = 0;
for (int i = 0; i < arg->size; ++i)
*sum += __[2]__;
return sum;
}
int main(void) {
pthread_t t1, t2;
arg_t arg1 = {__[3]__, 500}, arg2 = {x + 500, __[4]__};
pthread_create(&t1, NULL, sum_array, __[5]__);
pthread_create(&t2, NULL, __[6]__, &arg2);
int *sum1, *sum2;
pthread_join(t1, __[7]__);
pthread_join(t2, __[8]__);
int sum = *sum1 + *sum2;
printf("sum is = %d\n", sum);
}