Skip to content

Instantly share code, notes, and snippets.

@avi007i
Created May 26, 2018 23:35
#include <iostream>
#include <atomic>
using namespace std;
int main()
{
atomic<int> x{ 0 };
int z = 98;
// Read
int y = x.load();
cout << "y = " << y << '\n';
// Write
x.store(z);
cout << "x = " << x << '\n';
// Read Modify Write
x++;
cout << "x = " << x << '\n';
}
/* Output
y = 0
x = 98
x = 99
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment