====== 2012.05.01 - UB in C++11 threads ====== recently i've wrote [[blog:2012:04:06:2|how bad undefined behavior is]]. when it is obvious for everyone, it is worth noticing that memory model of [[wp>C++11]] ensures sequential consistency for data-race-free programs only! it means that if you read and write from multiple threads, to the same variable, neither protected by mutex, nor being atomic (i.e. //std::atomic//), your program uses UB and compiler can do ANYTHING with it. even if compiler won't accidentally "break" any thing you can still crash on "funny" effects of non-atomic access to some of the variables. i highly recommend you watching Hans Boehm's talk on [[http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Threads-and-Shared-Variables-in-C-11|threads and shared variables in C++11]]. many tricks and pitfalls are explained. enjoy... :)