Skip to content

Instantly share code, notes, and snippets.

@why-jay
Created January 24, 2015 06:45
Show Gist options
  • Save why-jay/f734c35e074291747863 to your computer and use it in GitHub Desktop.
Save why-jay/f734c35e074291747863 to your computer and use it in GitHub Desktop.
#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