Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
447 views
in Technique[技术] by (71.8m points)

c++ - is_lock_free() returned false after upgrading to MacPorts gcc 7.3

Previously, with Apple LLVM 9.1.0, is_lock_free() on 128-bit structures have returned true. To have complete std::optional support, I then upgraded to MacPorts gcc 7.3. During my first try to compile, I encountered this notorious showstopper linker error:

Undefined symbols for architecture x86_64:
  "___atomic_compare_exchange_16", referenced from:

I know that I may need to add -latomic. With Apple LLVM 9.1.0, I don't need it, and I have a very bad feeling about this. If it's lock-free, you usually should not need to link to any additional library, the compiler alone is able to handle it. Otherwise, it may just be lock-based and require support from additional library. Just as I have feared, after adding -latomic, build succeeded, but is_lock_free() returned false.

I do think gcc 7.3 and its standard library implementation are fine. It may just be some configuration problem on my side. As a matter of fact, I didn't do any configuration. I simply installed the MacPorts gcc and done. Any idea what I may be missing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Found the answer myself here.

gcc7 and later will call libatomic instead of inlining lock cmpxchg16b, and will return false from atomic_is_lock_free (for reasons including that it's so slow it's not what users expect is_lock_free to mean), but at least for now the libatomic implementation still uses lock cmpxchg16b on targets where that instruction is available. (It can even segfault for read-only atomic objects, so it's really not ideal.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...