Question: 2. Suppose that instead of using a two-dimensional array for the indices, we use a one dimensional array of size 3 and do the index

 2. Suppose that instead of using a two-dimensional array for the

2. Suppose that instead of using a two-dimensional array for the indices, we use a one dimensional array of size 3 and do the index calculation inside the same loop that creates the threads. In that loop, we will pass the indices of one thread at a time as detailed in the following code int indices[3] subarraySize- arraySize/thrdCnt startlndx-0 endindx - subarray Size-1 fori-0; igThreadCount, i++) indices[0] = i; indices[1] startlndx, if (ithreadCount-1) endlndx- arraySize-1 indices[2] endlndx, pthread_create(tid+i, attr+i, Child, indices) startlndx endlndx 1 endindx +subarraySize The above approach is incorrect. Identify the bug in the above code and give a specific scenario in which something wrong will happen. Hint: Think of the problem from parallel programming and multithreading point of view (3 points) 2. Suppose that instead of using a two-dimensional array for the indices, we use a one dimensional array of size 3 and do the index calculation inside the same loop that creates the threads. In that loop, we will pass the indices of one thread at a time as detailed in the following code int indices[3] subarraySize- arraySize/thrdCnt startlndx-0 endindx - subarray Size-1 fori-0; igThreadCount, i++) indices[0] = i; indices[1] startlndx, if (ithreadCount-1) endlndx- arraySize-1 indices[2] endlndx, pthread_create(tid+i, attr+i, Child, indices) startlndx endlndx 1 endindx +subarraySize The above approach is incorrect. Identify the bug in the above code and give a specific scenario in which something wrong will happen. Hint: Think of the problem from parallel programming and multithreading point of view (3 points)

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!