Atomic access to non-atomic memory location in C++11 and OpenMP?
问题 OpenMP, in contrast to C++11, works with atomicity from a perspective of memory operations, not variables. That allows, e.g., to use atomic reads/writes for integers being stored in a vector with unknown size at compile time: std::vector<int> v; // non-atomic access (e.g., in a sequential region): v.resize(n); ... v.push_back(i); ... // atomic access in a multi-threaded region: #pragma omp atomic write // seq_cst v[k] = ...; #pragma omp atomic read // seq_cst ... = v[k]; In C++11, this is not