I need to create an array of atomic integers i.e. n integers each of which are atomic. I found that std::vector<std::atomic<int>>
will not work but then I tried the following approach and it compiles successfully with clang.
int n;
std::cin >> n;
std::atomic<int> **a;
a = new std::atomic<int>* [n];
for(int i = 0; i < n; i++)
{
a[i] = new std::atomic<int>();
}
I'm not sure if doing this is correct, is it? Also, is there any method to verify if all the a[i][0]
will be atomic here(except for checking it with multiple threads)?