Question: Objective: Basically, I create an array with 10 elements inside main and create two threads. The first thread, calcOddIndex, will calculate the product of all
Objective: Basically, I create an array with 10 elements inside main and create two threads. The first thread, calcOddIndex, will calculate the product of all elements with odd index inside the array. The second thread, calcEvenIndex, will calculate the product of all elements with even index inside the array. Main will finally output the results after two child threads finish.
It gives me the error below. I think I am not passing the array correctly to the pthread_create. Please fix this so it accomplishes the objective above. Also, explain your revisions by commenting on the code

Here is my code:
#include#include #include /* first thread will calculate the product of all elements with odd index inside the array */ void *calcOddIndex(int arr[10]); int oddIndexProduct = 1; /* the second thread will calculate the product of all elements with even index inside the array */ void *calcEvenIndex(int arr[10]); int evenIndexProduct = 1; int main() { pthread_t tidOdd; /* the thread identifier for calcOddIndex */ pthread_t tidEven; /* the thread identifier for calcEvenIndex */ pthread_attr_t attr; /* set of thread attributes */ /* create an array with at least 10 elements */ int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; /* get the default attributes */ pthread_attr_init(&attr); /* create thread for calcOddIndex */ pthread_create(&tidOdd, &attr, calcOddIndex, &array); /* create thread for calcEvenIndex */ pthread_create(&tidEven, &attr, calcEvenIndex, &array); /* wait until both threads is done with their work */ pthread_join(tidOdd, NULL); pthread_join(tidEven, NULL); // print the product of all elements with odd index printf("product of odd index inside the array = %d ", oddIndexProduct); // print the product of all elements with even index printf("product of even index inside the array = %d ", evenIndexProduct); } // end of main /* calculate the product of all elements with odd index inside the array */ void *calcOddIndex(int arr[10]) { for (int i=1; i g++ -c -Werror main.cc main.cc:24:2: error: no matching function for call to 'pthread_create' pthread_create(&tidodd, Sattr, calcoddIndex, Sarray); /usr/include/pthread.h:326:5: note: candidate function not viable: no known conversion from 'void (int ) to 'void* Nullable(Nonnull) (void* Nullable) for 3rd argument int pthread_create(pthread_t-Nullable *-Nonnull-restrict, main.cc:26:2: error: no matching function for call to 'pthread_create' pthread_create(&tidEven, &attr, calcEvenIndex, Sarray) /usr/include/pthread.h:326:5: note: candidate function not viable: no known conversion from 'void *(int *)' to 'void *-Nullable (*-Nonnull) (void * Nullable) for 3rd argument int pthread_create(pthread_t-Nullable *-Nonnull-restrict, 2 errors generated. make: [main.ol Error 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
