I am reading about std::condition_variable on http://en.cppreference.com/w/cpp/thread/condition_variable and I don't understand this:
Even if the shared variable is atomic, it must be modified under the mutex in order to correctly publish the modification to the waiting thread.
Why a shared atomic variable is not properly published if it is not modified under mutex? How to understand this statement?
On another page http://en.cppreference.com/w/cpp/atomic/atomic there is a statement that seems to contradict to the the first statement:
If one thread writes to an atomic object while another thread reads from it, the behavior is well-defined (see memory model for details on data races)