vendredi 20 août 2021

Does std::thread constructor completion actually synchronize with the beginning of the thread of execution?

The C++11 standard (N337, 30.3.1.2) states about the synchronization of the std::thread constructor:

Synchronization: The completion of the invocation of the constructor synchronizes with the beginning of the invocation of the copy of f.

Reading it, I thought the constructor completes before the start of the new thread. But according to the question (std::thread construction and execution) and the current implementation in libc++/libstdc++, there seems no synchronization mechanism and the new thread of execution can possibly begin before the end of the std::thread constructor.

If that is correct, what does the standard try to say? Is this the gap between standard and implementation? Or do I understand the term "synchronize with" incorrectly? Even if constructor and new thread are running simultaneously, can the constructor completion be considered synchronizing with the beginning of new thread?

Aucun commentaire:

Enregistrer un commentaire