I want to do roughly this:
Initial thread:
- write some values to global vars (they will never be written again)
- This could be moderately large data (arrays, strings, etc). Cannot simply be made
std::atomic<>.
- This could be moderately large data (arrays, strings, etc). Cannot simply be made
- spawn other threads
Other threads:
- read the global state
- do work, etc.
Now, I know I can pass arguments to std::thread, but I'm trying to understand the memory guarantees of C++ through this example.
Also, I am pretty confident that on any real-world implementation, creating a thread will cause a memory barrier ensuring that the thread can "see" everything the parent thread wrote up until that point.
But my question is: is this guaranteed by the standard?
Aside: I suppose I could add some dummy std::atomic<int> or so, and write to that before starting the other threads, then on the other threads, read that once on startup. I believe all the happens-before machinery would then guarantee that the previously-written global state is properly visible.
But my question is if something like that is technically required, or is thread creation enough?