Do we need mfence when using xchg

前端 未结 4 1004
独厮守ぢ
独厮守ぢ 2021-01-02 16:03

I have a set and test xchg based assembly lock. my question is :

Do we need to use memory fencing (mfence, sfence or lf

4条回答
  •  星月不相逢
    2021-01-02 16:22

    According to Chapter 8 Bus Locking, of the Intel 64 and IA-32 Architectures Software Developer’s Manual, Volume 3A

    The memory-ordering model prevents loads and stores from being reordered with locked instructions that execute earlier or later.

    So the locked XCHG instruction acts as a memory barrier, and no additional barrier is needed.

提交回复
热议问题