Compiling the below with zero-initialized atomics under both g++ 4.7 and g++ 4.8.2 takes hours. Default-initialized atomics and zero-initialized non-atomic compile immediately.
#include <iostream>
#include <array>
#include <algorithm>
#include <atomic>
int main(int argc, char* argv[]) {
//std::array<std::atomic<int>, 1000000> arr; // default initialization (i.e., random data) = FAST
//std::array<int, 1000000> arr={{}}; // zero init non-atomic = FAST
//std::array<std::atomic<int>, 1000000> arr{{}}; // zero initialization = FOREVER
//std::array<std::atomic<int>, 1000000> arr={{}}; // zero init via assignment = FOREVER
std::array<std::atomic<int>, 1000000> arr{}; // zero initialization = FOREVER
std::cerr << "sum = " << std::accumulate(arr.begin(), arr.end(), 0) << std::endl;
}
g++ -std=c++11 array.cpp
Is the only option to memset the array manually?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With