c ++ 11等同于java atomiclongarray [英] c++ 11 equivalent of java atomiclongarray

查看:219
本文介绍了c ++ 11等同于java atomiclongarray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java库的C ++端口。其中一个问题是我不能找到等同于Java的AtomicLongArray。任何人都知道在c ++ 11中有什么已经等同的东西,或者如何实现类似的功能?我看看C ++ 11原子,但没有找到任何东西。

I am working on a C++ port of a Java library. One of the problems is I am not able to find equivalent of Java's AtomicLongArray. Anyone knows if there is anything already equivalent in c++ 11 or how to implement similar functionality? I had a look at C++11 atomics but could not find anything.

推荐答案

AtomicLongArray 说:


一个长数组,其中元素可能原子地更新。有关原子变量属性的描述,请参阅 java.util.concurrent.atomic 包规范。

这听起来像一个简单的数组 std :: atomic< long>

That sounds to me like a simple array of std::atomic<long>:

std::array<std::atomic<long>, N> array;
// or, if size is not known at compile time
std::vector<std::atomic<long>> vector(n);

请注意,只有元素是原子的,容器本身不是,所以不要绕过 push_back 进入向量。

Note that only the elements are atomic, the container itself isn't, so don't go around push_backing into the vector.

这篇关于c ++ 11等同于java atomiclongarray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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