Skip to content

Instantly share code, notes, and snippets.

@doorbash
Created November 7, 2019 15:24
Show Gist options
  • Save doorbash/6b5cf08c0279c6ebd24ccfc1e368f604 to your computer and use it in GitHub Desktop.
Save doorbash/6b5cf08c0279c6ebd24ccfc1e368f604 to your computer and use it in GitHub Desktop.
#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