Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does std::atomic_thread_fence have "C" linkage?

Tags:

c++

c++11

atomic

I have no guess as to why it would be desirable for this function to have "C" rather than "C++" linkage.

like image 561
WaltK Avatar asked Feb 01 '17 14:02

WaltK


1 Answers

That was added by LWG issue 1479 which was addressing a last-minute comment on C++11.

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

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

like image 75
Cubbi Avatar answered Nov 14 '22 01:11

Cubbi