Why does std :: atomic_thread_fence have a "C" link?

I do not know why it would be desirable for this function to have a "C" link, and not "C ++".

+5
source share
2 answers

This was added by LWG issue 1479 , which discussed the latest comment on C ++ 11.

The rationale for this change was C language compatibility (the C11 thread library has the identical atomic_thread_fence function in stdatomic.h).

As far as I understand, there has always been a plan in which C and C ++ atomic libraries can coexist: other compatibility examples are C type aliases for std :: atomic, such as atomic_int and C compatibility macro ATOMIC_VAR_INIT

+5
source

atomic_thread_fence sets the synchronization order of the memory of non-atomic and relaxed atomic accesses.
Concurrency, especially the relaxed concurrency memory, is a well-known thin and error-prone domain, and thus checking for such optimizations is of great interest. Ref1 .
CompCertTSO is widely used for such a thing.
CompCertTSO is a compiler that generates x86 assembly code from ClightTSO, a large subset of the C programming language extended with concurrency primitives for flow control and synchronization, and with a TSO attenuated memory model based on the x86-TSO model.

Thus, for verification, optimization, and testing, it is desirable that this function has a "C" relationship.

0
source

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


All Articles