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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -