The scenario is as follows:
- Create an instance of a class (std::map) and
sore it as global variable. - Spawn threads.
- Threads read and use the same global
instance of the class (call methods, access members etc) - All spawned threads quit
- Global class instance is destroyed
No mutex used, no spawn thread modifies the global class instance.
Is this OK?
Thank You
Typically yes, but it’s not a hard guarantee.
The core problem is that you need a memory barrier to make sure that the first thread writes back all data from registers to memory. However, it is very likely that this will happen when you create the second thread.