mardi 21 juillet 2015

How to create a new thread in accordance with specific conditions and join it later in C++11?

std::thread main;
if (/*check code here*/)
{
main = std::thread(thread_hunt);
 }
main.join();

This code will cause an error while main thread join if it is not initialized in the if-statement.

bool i=false;
std::thread main;
if (/*check code here*/)
{
main = std::thread(thread_hunt);
j=true;
}
if (j)
{
main.join();
}

The code works well,but is there a easier way I can achieve this goal?

Aucun commentaire:

Enregistrer un commentaire