升级到MacPorts gcc 7.3后,is_lock_free()返回false [英] is_lock_free() returned false after upgrading to MacPorts gcc 7.3

查看:178
本文介绍了升级到MacPorts gcc 7.3后,is_lock_free()返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前,对于Apple LLVM 9.1.0,128位结构上的is_lock_free()已返回true.为了获得完整的std::optional支持,我随后升级到了MacPorts gcc 7.3.在我第一次尝试编译时,我遇到了这个臭名昭著的showstopper链接器错误:

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:

我知道我可能需要添加-latomic.使用Apple LLVM 9.1.0,我不需要它,对此我感觉很不好.如果它是无锁的,通常不需要链接到任何其他库,仅编译器就能处理它.否则,它可能只是基于锁的,并且需要其他库的支持.就像我担心的那样,添加-latomic后,构建成功,但是is_lock_free()返回false.

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.

我确实认为gcc 7.3及其标准库实现很好.这可能只是我这方面的一些配置问题.事实上,我没有做任何配置.我只是简单地安装了MacPorts gcc并完成了.知道我可能会缺少什么吗?

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?

推荐答案

自己在此处找到答案.

gcc7及更高版本将调用libatomic而不是内联lock cmpxchg16b,并且将从atomic_is_lock_free返回false(出于种种原因,包括它是如此之慢以至于不是用户期望的is_lock_free意思),但是至少到目前为止,libatomic实现仍在可使用该指令的目标上使用lock cmpxchg16b . (它甚至可以对只读原子对象进行segfault,因此它确实不理想.)

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.)

这篇关于升级到MacPorts gcc 7.3后,is_lock_free()返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆