简体   繁体   English

std :: atomic_thread_fence具有未定义的引用

[英]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.

相关问题 这种std :: atomic_thread_fence的使用是否正确? - Is this use of std::atomic_thread_fence correct? atomic_thread_fence不是std的成员 - atomic_thread_fence is not a member of std std :: __ Atomic_thread_fence(大写A)正确吗? - std::_Atomic_thread_fence (with capital A) is this correct? 为什么这个 `std::atomic_thread_fence` 工作 - Why does this `std::atomic_thread_fence` work 为什么std :: atomic_thread_fence具有“ C”链接? - Why does std::atomic_thread_fence have “C” linkage? 在具有相同顺序的原子加载/存储之前使用 std::atomic_thread_fence 总是多余的吗? - Is using std::atomic_thread_fence right before an atomic load/store with the same order always redundant? 获取条件std :: atomic_thread_fence的优点和缺点是什么? - Benefits & drawbacks of as-needed conditional std::atomic_thread_fence acquire? 在 x86 上实现 std::atomic_thread_fence(std::memory_order_seq_cst) 没有额外的性能损失 - An implementation of std::atomic_thread_fence(std::memory_order_seq_cst) on x86 without extra performance penalties atomic_thread_fence(memory_order_release) 与使用memory_order_acq_rel 有什么不同? - Is atomic_thread_fence(memory_order_release) different from using memory_order_acq_rel? atomic_thread_fence(memory_order_seq_cst) 是否具有完整内存屏障的语义? - Does atomic_thread_fence(memory_order_seq_cst) have the semantics of a full memory barrier?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM