Skip to content

Instantly share code, notes, and snippets.

@DieHertz
Created July 22, 2014 09:51
Show Gist options
  • Save DieHertz/cc830bf10e075234251c to your computer and use it in GitHub Desktop.
Save DieHertz/cc830bf10e075234251c 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{[] {
r1 = x;
y = 1;
}};
auto th2 = std::thread{[] {
r2 = y;
x = 1;
}};
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