Is it dangerous to read global variables from separate threads at potentially the same time?
- 阅读更多 关于 Is it dangerous to read global variables from separate threads at potentially the same time?
So I'm writing this neat little program to teach myself threading, I'm using boost::thread and C++ to do so. I need the main thread to communicate with the worker thread, and to do so I have been using global variables. It is working as expected, but I can't help but feel a bit uneasy. What if the the worker thread tries write to a global variable at the same time as the main thread is reading the value. Is this bad, dangerous, or hopefully taken into account behind the scenes?? §1.10 [intro.multithread] (quoting N4140): 6 Two expression evaluations conflict if one of them modifies a memory