I have a shared object of type:
struct A {
int x;
int y;
int z;
};
A obj;
There is 2 threads running in parallel.
Thread #1 modifies object's members:
// .. some code before
obj.x = 42;
obj.y = 42;
obj.z = 42;
// .. now thread #2 can read obj
Thread #2 reads object's members:
// .. some code before
int x = obj.x;
int y = obj.y;
int z = obj.z;
// .. some code after
How to synchronize the flow most efficiently that the thread #2 reads object's members only after thread #1 modified them all?