The beginning of a new execution thread is sequenced only with the completion of std::thread
's constructor.
In the first version, the entire execution thread could theoretically run and finish before the original execution thread calls now
() for the first time. C++ gives you no guarantees whatsoever that the execution thread won't actually start and run only after the first call to now
.
The second version is guaranteed to cover the entire execution thread, plus a little bit of overhead of std::thread
's construction.
Even better would be to move the run time capture into the actual execution thread itself.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…