What's the difference between InterlockedCompareExchange Release() and Acquire()?

后端 未结 2 371
面向向阳花
面向向阳花 2020-12-18 03:14

What\'s the difference between InterlockedCompareExchangeRelease() and InterlockedCompareExchangeAcquire()?

When I try to learn the synchro

相关标签:
2条回答
  • 2020-12-18 03:37

    I found this and this on MSDN:

    Acquire memory semantics specify that the memory operation being performed by the current thread will be visible before any other memory operations are attempted. Release memory semantics specify that the memory operation being performed by the current thread will be visible after all other memory operations have been completed. These semantics allow you to force memory operations to be performed in a specific order. Use acquire semantics when entering a protected region and release semantics when leaving it.

    0 讨论(0)
  • 2020-12-18 03:47

    The plain version uses a full barrier while the suffixed versions only deals with loads or stores, this can be faster on some CPUs (Itanium-based processors etc)

    MSDN has a article about Acquire and Release Semantics and the Interlocked* API as well as this great blog post. The Linux memory barrier documentation might also be useful...

    0 讨论(0)
提交回复
热议问题