[英]std::atomic_thread_fence has undefined reference
On a Ubuntu 12.04 system when I try compiling the following code: 在Ubuntu 12.04系统上,当我尝试编译以下代码时:
#include <atomic>
int a;
int main()
{
a = 0;
std::atomic_thread_fence(std::memory_order_acquire);
a = 1;
}
I get an error message like: 我收到如下错误消息:
g++ test.cpp -std=c++0x
/tmp/ccayKntC.o: In function `main': test.cpp:(.text+0x14): undefined reference to `std::atomic_thread_fence(std::memory_order)' collect2: ld returned 1 exit status
This happens when compiling with clang++
also. 使用
clang++
编译时也会发生这种情况。 Since it is a linker error I guess that my version of libstdc++ lacks the necessary functionality. 由于这是一个链接器错误,我想我的libstdc ++版本缺少必要的功能。 However, other atomic operations seem to work.
但是,其他原子操作似乎可行。
I'm using Ubuntu 12.04. 我正在使用Ubuntu 12.04。 I'm wondering if there is a problem with my system setup, whether it is a missing feature from my libstdc++, or possibly something else.
我想知道我的系统设置是否有问题,它是否是我的libstdc ++中缺少的功能,或者可能是其他原因。 And ideally I'd like to be able to fix the problem.
理想情况下,我希望能够解决该问题。
This is actually a bug which was fixed in the 4.7 branch: 这实际上是一个错误,已在4.7分支中修复:
I think you need to use __sync_synchronize
or something like __asm__ __volatile__ ( "mfence" ::: "memory" )
我认为您需要使用
__sync_synchronize
或类似__asm__ __volatile__ ( "mfence" ::: "memory" )
Some people like to be very rigorous about which synchronization operation they need, but I think using mfence
all the time will suffice for common cases. 有些人喜欢对他们需要哪种同步操作非常严格,但是我认为,
mfence
使用mfence
足以满足常见情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.