对于大于32位的类型,clang不支持atomic :: is_lock_free吗?

时间:2017-07-27 09:10:43

标签: c++ compilation locking size atomic

我有以下内容:

struct A { int a[4]; };
struct B { int x, y; };
int main()
{
    std::cout << std::boolalpha
            << "std::atomic<A> is lock free? "
            << std::atomic<A>{}.is_lock_free() << '\n'
            << "std::atomic<B> is lock free? "
            << std::atomic<B>{}.is_lock_free() << '\n';
}

它编译并运行良好,但如果我提高A:

的大小
struct A { int a[5]; };
struct B { int x, y; };
int main()
{
    std::cout << std::boolalpha
            << "std::atomic<A> is lock free? "
            << std::atomic<A>{}.is_lock_free() << '\n'
            << "std::atomic<B> is lock free? "
            << std::atomic<B>{}.is_lock_free() << '\n';
}

好铿锵给出了错误:

Undefined symbols for architecture x86_64:
"___atomic_is_lock_free", referenced from:
    _main in atomics.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这是什么错误?是否需要额外的库“is_lock_free”才能使用更大的结构?

问题已解决,请使用“-latomic”链接标记!

0 个答案:

没有答案