I am trying to understand what is a memory barrier exactly.
Based on what I know so far, a memory barrier (for example: mfence
) is used to prevent the re-ordering of instructions from before to after and from after to before the memory barrier.
This is an example of a memory barrier in use:
instruction 1
instruction 2
instruction 3
mfence
instruction 4
instruction 5
instruction 6
Now my question is: Is the mfence
instruction just a marker telling the CPU in what order to execute the instructions? Or is it an instruction that the CPU actually executes like it executes other instructions (for example: mov
).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…