vendredi 18 août 2023

what happens if thread object is destroyed, but the thread isn't finish?

Suppose I have the following code:

//do job1;

{
   std::thread th(long_process_func);
   th.detach();
}

//do job2;

In the codes above, th is destroyed immediately after calling detach, but the thread isn't finished yet because the long process function. Is the code above safe?

It runs without any problem in my test, but not sure how it works

Aucun commentaire:

Enregistrer un commentaire