Created
November 7, 2019 15:24
-
-
Save doorbash/6b5cf08c0279c6ebd24ccfc1e368f604 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
#include <functional> | |
int main(int argc, char *argv[]) { | |
int x = 1; | |
std::cout << "[1] x is " << x << std::endl; | |
std::function<void()> f = [&](){ | |
x = 2; | |
std::cout << "[3] x is " << x << std::endl; | |
}; | |
std::thread t1(f); | |
std::cout << "[2] x is " << x << std::endl; | |
t1.join(); | |
std::cout << "[4] x is " << x << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment