In c++11, can std::atomic be used to transmit non-atomic data between two thread? In detail, are the following 4 semantics all established by atomic?
all statements(when talking about execution, including all machine instructions generated by those c++ statements) before an atomic-write statement are executed before the atomic-write.
all statements(when talking about execution, including all machine instructions generated by those c++ statements) after an atomic-read are executed after the atomic-read.
all other memory-write before writing an atomic are committed to main memory.
all other memory-read after reading an atomic will read from main memory again(that means discard thread cache).
I have seen an example here: http://bartoszmilewski.com/2008/12/01/c-atomics-and-memory-ordering/
However, in the example, the data is an atomic, so my question is, what if the data is non-atomic?
Here is some code, showing what i want:
common data:
std::atomic_bool ready;
char* data; // or data of any other non atomic
write thread:
data = new char[100];
data[0] = 1;
ready.store(true); // use default memory_order(memory_order_seq_cst), witch i think is the most restrict one
read thread:
if(ready.load()) { // use default memory_order(memory_order_seq_cst)
assert(data[0] == 1); // both data(of type char*) and data[0~99](each of type char) are loaded
}