When I run this code:
当我运行这个代码:
#include <iostream>
#include <thread>
#include <mutex>
std::mutex m;
int main()
{
std::vector<std::thread> workers;
for (int i = 0; i < 10; ++i)
{
workers.emplace_back([i]
{
std::lock_guard<std::mutex> lock(m);
std::cout << "Hi from thread " << i << std::endl;
});
}
std::for_each(workers.begin(), workers.end(), [] (std::thread& t)
{ t.join(); });
}
#include <i