vendredi 21 février 2020

Is joinable() then join() thread-safe in std::thread?

In a std::thread, an exception is throw if I call join() and the thread is not joinable.

So I do :

if (thread.joinable())
  thread.join();

Now imagine that the thread is terminated after the joinable() and before the join() (due to thread scheduling).

Is this case possible in the worth situation ? Do I really need to use a try / catch around join() ?

Aucun commentaire:

Enregistrer un commentaire