std::memory_order_acquire barrier guarantees that all the operations such as read/write which goes after the barrier will be performed after all the reading(load) operations before the barrier.
For example, i have a following code:
#include <iostream>
#include <atomic>
int num = 25;
int getValue()
{
return num;
}
void setValue(int value)
{
num = value;
}
int main()
{
std::atomic<int> n;
int data = getValue();
n.store(data, std::memory_order_acquire);
setValue(100);
std::cout << getValue();
}
Can i be sure that code int data = getValue();
guaranteed will be performed before following code?
n.store(data, std::memory_order_acquire);
setValue(100);
std::cout << getValue();
At the atomic storing moment, int data = getValue()
guaranteed be performed. I am right?