Init: int x = y = 0;
thr1 thr2
---- ----
y = 1; x = 1; WRITE to global variables
a = x; b = y; READ from global variables
print(a); print(b);
In the above code snippet running under the TSO memory model, it is well known that both threads can print 0
at the same time because a CPU can re-order instructions to execute a read instruction (i.e., the second line of a thread) before a write instruction.
Then, what will happen we insert breakpoints on the read instructions, and do nothing but keep executing when breakpoints are hit? Still can both threads print 0
at the same time, or do breakpoints prevent reordering?
I assume the x86-64 architecture and the x86-TSO memory model. It though will be appreciated if any difference between architectures (or memory models) is given. Also I guess hardware breakpoint and software breakpoint will not make a difference in result (since they both trigger an exception, and the x86 architecture handles them similarly). Is this guessing correct?