Question: #include #include #include /* Compile as gcc pthread_join_example.c -o join_example */ typedef struct { int *array; int n; } subarray; void * print_array(void *arg) {

#include
/* Compile as gcc pthread_join_example.c -o join_example */
typedef struct { int *array; int n; } subarray;
void * print_array(void *arg) { int i;
for (i = 0; i n; i++) { ((subarray *)arg)->array[i]++; printf("array[%d] is: %d ",i,((subarray *)arg)->array[i]);
} return NULL; }
int main(void) { int l=100,main_array[l], i; pthread_t th1, th2; subarray sb1, sb2;
for (i=0; i sb1.array = &main_array[0]; sb1.n = 50; (void) pthread_create(&th1, NULL, print_array, &sb1); (void) pthread_join(th1, NULL); sb2.array = &main_array[50]; sb2.n = 50; (void) pthread_create(&th2, NULL, print_array, &sb2); //(void) pthread_join(th1, NULL); (void) pthread_join(th2, NULL); return 0; } Change the code in pthread_join_example.c so that it creates and uses exactly three threads to do the same job that it was doing originally. Put this new program into a file called pthread_join_example3.c
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
