Interference Between Two Threads of Control
Two parallel threads of control (processes, threads) P1, P2
Both threads of control increment a common variable, Value
Initially Value = 0
Case with Interference
P1 P2 Register Value
1 Load 0 0
• Interrupt (Context Switch), P1 process (thread) state will be remembered, including content of
the registers
2 Load 0 0
3 Inc 1 0
4 Store 1 1
• Restore from interrupt, content of registers restored to the point before interrupt
5 Inc 1 1
6 Store 1 1
Finally, Value = 1
Due to interference, in this case final value is 1.
Case without Interference
P1 P2 Register Value
1 Load 0 0
2 Inc 1 0
3 Store 1 1
4 Load 1 1
5 Inc 2 1
6 Store 2 2
Finally, Value = 2 (expected result)