2

When a thread is done executing- how does updates to the memory handled? Is it guaranteed that all the writes would be flushed to the main memory and visible to other threads? For e.g.

std::vector<std::thread> threads;
std::vector<int> result(32);
for(int i = 0; i < 32; ++i) {
    threads.emplace_back(do_something, std::ref(result[i]));
}
for(int i = 0; i < 32; ++i) threads[i].join(); 

std::accumulate(result.begin(), result.end(), 0;  // 1)

Is the result vector guaranteed to have the correct results without any explicit synchronization and safe to be used in std::accumulate?

Thanks

0 Answers0