Created
July 22, 2014 09:51
-
-
Save DieHertz/cc830bf10e075234251c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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