Skip to content

Instantly share code, notes, and snippets.

@DieHertz
Created July 21, 2014 13:05
Show Gist options
  • Save DieHertz/96f073b74872260e9792 to your computer and use it in GitHub Desktop.
Save DieHertz/96f073b74872260e9792 to your computer and use it in GitHub Desktop.
#include <thread>
#include <atomic>
#include <iostream>
int x, y;
int r1, r2;
int main() {
auto th1 = std::thread{[] {
y = 1;
r1 = x;
}};
auto th2 = std::thread{[] {
x = 1;
r2 = y;
}};
th1.join();
th2.join();
std::cout << r1 << ' ' << r2 << '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment