The C++11 standard section 30.3.1.2 thread constructors [thread.thread.constr] p5 describes the constructor template <class F, class... Args> explicit thread(F&& f, Args&&... args)
:
Synchronization: the completion of the invocation of the constructor synchronizes with the beginning of the invocation of the copy of
f
.
So everything in the current thread happens before the thread function is called. You don't need to do anything special to ensure that the assignments to the Worker
members are complete and will be visible to the new thread.
In general, you should never have to use a memory fence when writing multithreaded C++11: synchronization is built into mutexes/atomics and they handle any necessary fences for you. (Caveat: you are on your own if you use relaxed atomics.)