Question: please i need answer to this problem. Thanks Consider the following code that creates N threads using the POSIX threading library. The thread function threadFun

please i need answer to this problem. Thanks

Consider the following code that creates N threads using the POSIX threading library. The thread function threadFun receives as parameter a thread index (from 0 to N-1).

#define NTHREADS 4 // number of test threads void* threadFun(void* p) { LINE A // remainder of the function is irrelevant for this question

} void main() { int i; pthread_t tid[N]; pthread_attr attr; pthread_attr_init(&attr);

for (i=0; i

... // remainder of the function is irrelevant for this question

}

What is the right set of statements for LINE A and LINE B that correctly initialize the thread index variable from 0 to N-1, regardless of the timing of each thread's scheduling?

HINT: watch for memory that can be modified inadvertently by other threads.

a. LINE A: index = *(int*)p; LINE B: pthread_create(&tid[i], &attr, threadFun, &i);

b. LINE A: index = *(int)p; LINE B: pthread_create(&tid[i], &attr, threadFun, &i);

c. LINE A: index = (int)*p; LINE B: pthread_create(&tid[i], &attr, threadFun, (void*)i);

d. LINE A: index = (int)p; LINE B: pthread_create(&tid[i], &attr, threadFun, (void*)i);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!