Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <thread>
- #include <algorithm>
- using namespace std;
- //g++ tutorial2.cpp -std=c++0x -lpthread
- int main()
- {
- vector<thread> workers;
- for( int i = 0; i < 10; ++i )
- {
- workers.push_back(thread([i]()
- {
- printf("Hi from thread %i\n",i);
- //cout << "Hi from thread " << i << endl;
- }));
- }
- cout << "Hi from main!\n";
- for_each(workers.begin(), workers.end(), [](thread &th)
- {
- th.join();
- });
- return 0;
- }
Add Comment
Please, Sign In to add comment