"All non-local variables with thread-local storage duration are initialized as part of thread launch, sequenced-before the execution of the thread function begins." (https://en.cppreference.com/w/cpp/language/initialization)
However, cppreference does not seem to mention whether or not those variables are actually initialised by the thread that is being launched, or by the thread that is launching the new thread.
Consider the following example:
(id.hpp)
#include<thread>
extern thread_local const std::thread::id this_thread_id;
(id.cpp)
#include "id.hpp"
thread_local const std::thread::id this_thread_id = std::this_thread::get_id();
If I access this_thread_id from a thread that is not the main thread, am I going to get the id of that thread? If this_thread_id is initialised "as part of the thread launch", it might as well be initialised by the original calling thread, and as such this_thread_id would have an incorrect value.
I understand that there are design patterns to avoid this problem altogether, but that defeats the whole point of this question, so I don't want to use them here.