The difference between asm, asm volatile and clobbering memory

前端 未结 3 1950
时光说笑
时光说笑 2020-12-02 05:11

When implementing lock-free data structures and timing code it\'s often necessary to suppress the compiler\'s optimisations. Normally people do this using asm volatile

3条回答
  •  误落风尘
    2020-12-02 06:09

    Just for completeness on Lily Ballard's answer, Visual Studio 2010 offers _ReadBarrier(), _WriteBarrier() and _ReadWriteBarrier() to do the same (VS2010 doesn't allow inline assembly for 64-bit apps).

    These don't generate any instructions but affect the behaviour of the compiler. A nice example is here.

    MemoryBarrier() generates lock or DWORD PTR [rsp], 0

提交回复
热议问题