Consider a program with three threads A,B,C.
They have a shared global object G.
I want to use an atomic variable(i) inside G which is written by Thread B and Read by A.
My approach was:
declare i in G as:
std::atomic<int> i;
write it from thread B using a pointer to G as:
G* pG; //this is available inside A and B pG->i = 23;
And read it from thread A using the same way.
int k = pG->i;
Is my approach correct if these threads try to access this variable simultaneously.?