clang doesn't support atomic::is_lock_free for types larger than 32 bits?

☆樱花仙子☆ 提交于 2019-12-11 06:25:21

问题


I've got the following:

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';
}

It compiles and works well, but if I raise the size of 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';
}

Well clang gives error:

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)

What kind of error is this? Does it require extra library for "is_lock_free" to work with bigger structures?


Problem fixed, use "-latomic" linking flag!

来源:https://stackoverflow.com/questions/45346246/clang-doesnt-support-atomicis-lock-free-for-types-larger-than-32-bits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!