Created
March 13, 2015 11:38
-
-
Save alekseyl1992/4a021dad48927a4b4927 to your computer and use it in GitHub Desktop.
threads
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 <iostream> | |
#include <thread> | |
int main() | |
{ | |
for (int i = 0; i < 1000; ++i) { | |
int a = 5; | |
int b = 5; | |
int sum = 0; | |
std::thread th1([&]() { | |
a = 3; | |
b = 1; | |
}); | |
std::thread th2([&]() { | |
if (b == 1) { | |
sum += a; | |
if (sum != 3) | |
exit(-1); | |
} | |
}); | |
th1.join(); | |
th2.join(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment