InterlockedCompareExchange on Windows, as well as __sync_val_compare_and_swap in gcc accept pointers, and so I can pass any address, for example. pointing to a shared memory block for these functions.
For non-x86 architectures, I may need to ensure correct memory alignment, and for x86 (and possibly others), perhaps I want to ensure line alignment for performance, although correctness should not be a problem (-> x86 LOCK ).
Trying to get rid of some platform-dependent things in my code (Windows VC ++ vs GCC), I looked at C ++ 11 atomic_compare_exchange_weak and friends. But they all work with a variable like std::atomic<T>* .
Is there a way to use arbitrary pointers with C ++ 11 atomic functions? This is not like a simple cast to std :: atomic that will help solve this problem.
source share