samedi 28 avril 2018

Does a thread start immediately

I just started reading C++ Concurrency In Action 2012.pdf. In Chap 2 it shows a thread being invoked and joined. with the join not being an atomic operation with thread creation. By this I mean that the thread is started with std:thread t(...) and in a succeeding line a join is performed. My assumption is that when a thread is created it can begin executing at any time, including at once. And if it begins executing at once and terminates before the creating program begins executing, then the join fails.

The same issue occurs when if t.joinable()) is used.

If my guess is correct then there is no guarantee that a join can ever be successful and the joinable() predicate does not help. What am I missing?

Aucun commentaire:

Enregistrer un commentaire