c++ - vector of atomics fully thread safe? -
i have std::vector<std::atomic<size_t>>
vec. safe run vec[index].fetch_add(1, std::memory_order_release)
or store/load multiple concurrent threads on it? think should be, because reading thread safe , writing 1 entry @ same time multiple threads impossible because of atomics - right?
no not, in general, thread safe since container not atomic.
that said, long don't change in vector (i.e. doing invalidates return of data()
) , you'll fine.
sadly can't resort std::atomic<std::vector<...>>
std::vector
not trivially copyable.
Comments
Post a Comment