Sunday, 18 August 2013

C++11 memory model and accessing different members of the same struct in different threads

C++11 memory model and accessing different members of the same struct in
different threads

Assume you've got the following definitions:
struct X
{
char a, b;
};
X x;
And now assume you have two threads, one of which reads and writes x.a but
never accesses x.b while the other one reads and writes x.b but never
accesses x.a. Neither thread uses any locks or other synchronization
primitives. Is this guaranteed to work in C++11? Or does it count as
accessing the same object, and therefore need a lock?

No comments:

Post a Comment