Suppose we have an array of size $n$ which stores random numbers. Also, we have $n$ threads each of which should sum the numbers stored in the array positions from 0 to $m$-1 where $m$ is the number of that thread, then stores the result in the position $m$-1.
215
0
25
1
17
1001
2
3
...
...
5
-150
n-2
n-1
Apparently the threads can run independently, but when the array inspected after execution the results were incorrect.
a) Why the results were incorrect? What is this problem called? (4 marks)
b) How can such case be handled in order to always guarantee correct results? Suggest the most appropriate solution for this case and justify your choice. (5 marks)
Note: No code or mathematical examples or solutions required in your answer.