2012.05.01 - UB in C++11 threads

recently i've wrote how bad undefined behavior is. when it is obvious for everyone, it is worth noticing that memory model of 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<T>), 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 threads and shared variables in C++11. many tricks and pitfalls are explained. enjoy… :)

blog/2012/05/01/1.txt · Last modified: 2013/05/17 19:08 (external edit)
Back to top
Valid CSS Driven by DokuWiki Recent changes RSS feed Valid XHTML 1.0