原子对于年龄较大的 c++编译器

发布于 2024-12-03 11:54:32 字数 171 浏览 4 评论 0原文

我在代码中使用了atomic,但是我现在正在编译的机器有一个旧的g++版本,不支持C++11。网上是否有任何等效的类,以便我可以在我的代码中使用它,或者如果没有,我可以在其中找到 atomic 的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

野心澎湃 2024-12-10 11:54:32

提议的(即非官方的) 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

顾铮苏瑾 2024-12-10 11:54:32

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

合久必婚 2024-12-10 11:54:32

sig_atomic_t

这是一个对象的整型类型,可以作为
原子实体,即使存在异步信号也是如此。

在 gcc 中是 原子

为了避免中断访问变量的不确定性,您可以使用始终原子访问的特定数据类型:sig_atomic_t。

sig_atomic_t

This is an integral type of an object that can be accessed as an
atomic entity, even in the presence of asynchronous signals.

in gcc is atomic

To avoid uncertainty about interrupting access to a variable, you can use a particular data type for which access is always atomic: sig_atomic_t.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文