在 2024-04-24 00:18, Antonin Décimo 写道:
I couldn't find the difference between MemoryBarrier and _ReadWriteBarrier. Maybe the MemoryBarrier macro is available on more architectures than _ReadWriteBarrier which is only documented for x86 and x64?
`MemoryBarrier()` is a macro defined in 'winnt.h'. As a rule of thumb I think we had better avoid inclusion of Windows headers in our headers, especially headers that may be included by standard libraries.
If there's no problems using _ReadWriteBarrier, it seems like the easiest solution. I'd suggest moving to C11 atomic_thread_fence [1], but MSVC likely misses support…
Strangely that MSVC has only gained C11 atomic recently, and requires `/std:c11 /experimental:c11atomics`. So it yet results in more complexity which I think we had better avoid:
#if defined __GNUC__ || defined __clang__ /* GCC or Clang-CL */ # define __pthread_MemoryBarrier() \ __sync_synchronize() /* __atomic_thread_fence(__ATOMIC_SEQ_CST) */ #elif defined __cplusplus && (__cplusplus >= 201103L) /* C++11 */ # include <atomic> # define __pthread_MemoryBarrier() \ ::std::atomic_thread_fence(::std::memory_order_seq_cst) #else /* C11 */ # include <stdatomic.h> # define __pthread_MemoryBarrier() \ atomic_thread_fence(memory_order_seq_cst) #endif -- Best regards, LIU Hao
OpenPGP_signature.asc
Description: OpenPGP digital signature
_______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public