Correct sum with local variable?

Hi DQ Community,

Something I do not understand concerning the update of a local variable for the sum function.

If each process updates a local variable separately and later updates the shared_value when it has access to (depending on the lock condition), how come do we get the correct sum?

The first process will sum from 1 to 4,999 and the second one from 5,000 to 10,000. But the result of each should be summed to yield the sum from 1 to 10,000. And here I understand from the course explanation that whichever process finishes last will update the shared_value, ultimately giving half of the desired sum.

The solution with the implementation of a local variable is only explained with text at the end of this course. I think it would help to have a graphical animation as for the previous technical solution where we are explained how each process alternatively get the lock.

Many thanks

Antoine

Hi @antoine.purier:

Please attach the mission link and your code as per these guidelines so we know the particular mission you are referring to. Thanks!