I have a global shared variable and that is being updated 5 times by each of the 5 threads spawned. As per my understanding the increment operation is consisting of 3 instructions
load reg, M
inc reg
store reg, M
因此,我要问,在这种情形下,在5条深线中任意搭桥会带来最大和最低价值。
So according to me the maximum value will be 25 ( I am 100% sure that it can be more than 25) and the minimum value is 5. But I am not so sure on minimum value. Can it be less that 5 in some arbitrary interleaving ? Any inputs will be greatly appreciated.
/* Global Variable */
int var = 0;
/* Thread function */
void thread_func()
{
for(int c = 0; c < 5; c++)
var++;
}