As described in title I'd like to know whether tasks runned with std::async can "reuse" idle threads.
For example lets take next code:
auto task = []() { std::this_thread::sleep_for(std::chrono::seconds(20)); };
int tasksCount = 160;
std::vector<std::future<void>> futures;
for (int i = 0; i < tasksCount; ++i)
{
futures.push_back(std::async(task));
}
So we have a lot of tasks (160) runned in parallel which do nothing. When this code is running on windows it generates 161 waiting threads.
Isn't it too much threads for doing nothing? Why waiting threads can't be "reused"?
Aucun commentaire:
Enregistrer un commentaire