#include <iostream>
#include <thread>
#include <algorithm>
#include <vector>
using std::cout;
using std::endl;
using std::thread;
using std::vector;
class TestThread
{
public:
void operator()()
{
cout << "TestThread " << std::this_thread::get_id() << endl;
}
};
int main()
{
vector<thread> obj;
for (int i = 0; i < 5; i++)
{
obj.push_back(thread(TestThread()));
}
cout << "thread still works" << endl;
std::for_each(obj.begin(), obj.end(), std::mem_fn(&std::thread::join));
cout << "end main()" << endl;
return 0;
}
/*
run:
TestThread 13816 thread still works
TestThread 14868
TestThread 14536
TestThread 15332
TestThread 6508
end main()
*/