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!
source share