[英]Why does std::atomic_thread_fence have “C” linkage?
我不知道为什么希望此功能具有“ C”而不是“ C ++”链接。
That was added by LWG issue 1479 which was addressing a last-minute comment on C++11. LWG问题1479在解决有关C ++ 11的最新评论时对此进行了补充。
The rationale for this change was C language compatibility (C11 thread library has identically-named function atomic_thread_fence in stdatomic.h). 进行此更改的理由是C语言兼容(C11线程库在stdatomic.h中具有相同名称的函数atomic_thread_fence )。
As far as I understand, it was always a plan that C and C++ atomic libraries can coexist: other examples of compatiblity are the C-compatible type aliases for std::atomic, such as atomic_int
and the C-compatibility macro ATOMIC_VAR_INIT 据我了解,C和C ++原子库始终可以共存是一个计划:兼容性的其他示例是std :: atomic的C兼容类型别名,例如
atomic_int
和C兼容性宏ATOMIC_VAR_INIT
atomic_thread_fence
establishes memory synchronization ordering of non-atomic and relaxed atomic accesses. atomic_thread_fence
建立非原子访问和宽松原子访问的内存同步顺序。
Concurrency, especially relaxed-memory concurrency, is a notoriously subtle and error-prone domain, and so verifying such optimisations is of great interest. 并发,尤其是宽松的内存并发,是一个众所周知的微妙且容易出错的领域,因此验证这种优化非常令人感兴趣。 Ref1 .
参考1 。
For such thing is widely used CompCertTSO . 为此, CompCertTSO被广泛使用。
CompCertTSO is a compiler that generates x86 assembly code from ClightTSO, a large subset of the C programming language enhanced with concurrency primitives for thread management and synchronisation, and with a TSO relaxed memory model based on the x86-TSO model. CompCertTSO是从ClightTSO生成x86汇编代码的编译器,ClightTSO是C编程语言的大子集,并增强了用于线程管理和同步的并发原语,以及基于x86-TSO模型的TSO宽松内存模型。
So, for verification, optimisation and testing purposes is desirable for this function to have "C" linkage. 因此,出于验证,优化和测试的目的,希望此功能具有“ C”链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.