What is the difference between InterlockedCompareExchange Release () and Acquire ()?

What is the difference between InterlockedCompareExchangeRelease() and InterlockedCompareExchangeAcquire() ?

When I try to learn the synchronization functions using the WIN32 API, I find that there are two functions named differently, but seem to do the same thing:

 LONG __cdecl InterlockedCompareExchangeRelease( __inout LONG volatile *Destination, __in LONG Exchange, __in LONG Comparand ); 

and

 LONG __cdecl InterlockedCompareExchangeAcquire( __inout LONG volatile *Destination, __in LONG Exchange, __in LONG Comparand ); 

I check MSDN, it says these functions:

Performs an atomic comparison and exchange operation at the specified values. The function compares the two specified 32-bit values ​​and exchanges with another 32-bit value, based on the results of the comparison.

but for InterlockedCompareExchangeAcquire() ,

The operation is performed using memory access semantics.

and for InterlockedCompareExchangeRelease() ,

The exchange is carried out using the semantics of access to the release memory.

So I'm curious about the difference between the two functions. When to use access semantics to acquire memory or free memory ? Are there any examples?

Thanks!

+6
source share
2 answers

The simple version uses a complete barrier, while the suffix versions deal with downloads or , it can be faster on some processors (Itanium-based processors, etc.)

There is an article on MSDN about Get and Release Semantics and the Interlocked * API , as well as this great blog post . Linux memory protection documentation may also be useful ...

+8
source

I found this and this on MSDN:

When acquiring memory semantics, specify that the memory operation performed by the current thread will be visible before any other memory operations are undertaken. The semantics of memory semantics indicate that the memory operation performed by the current thread will be visible after all other memory operations are completed. This semantics allows you to force memory operations in a specific order. Use the semantics of getting at the entrance to the protected area and the release of semantics at its exit.

+1
source

Source: https://habr.com/ru/post/911056/


All Articles