Created
January 24, 2015 06:45
-
-
Save why-jay/f734c35e074291747863 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 <vector> | |
using namespace std; | |
int main() | |
{ | |
vector<thread> workers; | |
for (int i = 0; i < 5; ++i) | |
{ | |
// notice the [=], which means capture by copy | |
workers.push_back(thread([=] { cout << i; })); | |
} | |
for (thread& t: workers) t.join(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment