I have a global shared variable that is updated 5 times by each of the 5 threads generated. In my opinion, the increment operation consists of 3 instructions
load reg, M
inc reg
store reg, M
So, I want to ask that in this scenario there would be a maximum and minimum value for random rotation in 5 threads.
Thus, in my maximum value there will be 25 (I am 100% sure that it can be more than 25), and the minimum value is 5. But I am not sure about the minimum value. Could it be less than 5 with some arbitrary alternation? Any input would be much appreciated.
int var = 0;
void thread_func()
{
for(int c = 0; c < 5; c++)
var++;
}
source
share