dimanche 24 avril 2016

More than 2 threads at same time not working C++

When I try to use two threads, all is perefect:

#include <thread>  

std::thread t([&] {
while (1) {};
});

std::thread t1([&] {
while (1) {};
});

if (t.joinable()) { t.join(); }
if (t1.joinable()) { t1.join(); }

But when I try to use 3 threads it fails with "resouse unavailable try again":

#include <thread>

std::thread t([&] {
while (1) {};
});

std::thread t1([&] {
while (1) {};
});

std::thread t2([&] {
while (1) {};
});

if (t.joinable()) { t.join(); }
if (t1.joinable()) { t1.join(); }
if (t2.joinable()) { t2.join(); }

PS: i5 4690k, windows 7 64, use last version of VS if it is matter

Aucun commentaire:

Enregistrer un commentaire