If I use a shared variable, say double, to calculate some amount of program execution. Will it be vulnerable to unstable operations anyway? I mean, is it possible that more than one core will access this variable asynchronously and cause erratic results?
For example: this is a global variable:
double totalTime = 0;
and in each core the command is called:
totalTime += elapsedTime;
This last operation / statement is executed, taking the value totalTime, put it in the CPU register, and then add it. I can imagine that more than one core will take the same value at the same moment, and then add a new elapsedTime, and then the value stored in totalTime will be overwritten with the wrong value due to the delay. Is it possible? and how can i solve this?
Thank.
user1442235
source
share