Skip to content

Instantly share code, notes, and snippets.

@alekseyl1992
Created March 13, 2015 11:38
Show Gist options
  • Save alekseyl1992/4a021dad48927a4b4927 to your computer and use it in GitHub Desktop.
Save alekseyl1992/4a021dad48927a4b4927 to your computer and use it in GitHub Desktop.
threads
#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