原子对于年龄较大的 c++编译器
我在代码中使用了atomicatomic
的 C++11 实现,以便我可以复制从那里开始。这很容易做到吗?
I am using atomic<int>
in my code, but the machine in which now I'm compiling has an older g++ version which doesn't support C++11. Is there any equivalent class available on the net, so that I can use it in my code, or if not, where I can find the C++11 implementation of atomic<int>
so I can copy it from there. Can this be easily done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
提议的(即非官方的) Boost.Atomic 库旨在准确地做到这一点这。我不知道它目前处于什么状态,但它用于实施最近(官方)接受的Boost.Lockfree 库,所以想必它是可用的。
编辑 - 更新了链接,现在 Atomic 和 Lockfree 已经正式加入 Boost 一段时间了:
Boost.Atomic
Boost.Lockfree
The proposed (i.e. unofficial) Boost.Atomic library aims to do exactly this. I don't know what state it's in currently, but it's used in the implementation of the recently (officially) accepted Boost.Lockfree library, so presumably it's usable.
EDIT — updated links, now that both Atomic and Lockfree have officially been in Boost for some time:
Boost.Atomic
Boost.Lockfree
Hans Boehm 的原子操作库 很好,尽管很难确定上面有什么可用的各种平台。
如果您对 LGPL 感到满意,英特尔 TBB 也有您想要的东西(还有很多其他东西)。
如果您仅查看 GCC,那么您可能只需使用 GCC 的内在函数(我不确定它们出现在哪个版本的 GCC 中,但它们已经存在了一段时间)。
Hans Boehm's atomic ops library is good, although it's hard to determine what's available on various platforms.
If you're OK with the LGPL, Intel TBB has what you're looking for as well (plus a lot of other stuff).
If you're only looking at GCC, then you may be able to get away with just using GCC's intrinsics (I'm not sure which version of GCC those showed up in, but they've been around for a while).
sig_atomic_t
在 gcc 中是 原子
sig_atomic_t
in gcc is atomic