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.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- Sorting 3 numbers without branching [closed]
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
In [container.requirements.dataraces] the standard says
So any container (except evil
vector<bool>
) allows separate elements to be updated without data races. To also ensure updates to a single element are safe, use a container of atomic types, e.g.std::vector<std::atomic<long>>
The docs for AtomicLongArray say:
That sounds to me like a simple array of
std::atomic<long>
:Note that only the elements are atomic, the container itself isn't, so don't go around
push_back
ing into the vector.