https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67436
--- Comment #2 from Johannes S. Mueller-Roemer <j.s.mueller-roemer at gmx dot net> --- (In reply to Jonathan Wakely from comment #1) > (In reply to Johannes S. Mueller-Roemer from comment #0) > > I encountered an error with a missing __tls_init after using a thread_local > > variable within a generic lambda. I was able to work around this bug by > > creating a reference to the thread_local and using the reference in the > > lambda instead. > > That sounds similar to an example discussed by the committee recently: > > void f() { > thread_local int n = 10; > std::thread([&] { std::cout << n << std::endl; }).join(); > } Yes, however in this case the lambda is called in the same thread in which it is created. > The reference to n inside the lambda is to the variable in the new thread, > which was never initialized because the flow of control never reached its > initializer. This is probably a defect in the standard. Odd, I would expect the reference to be evaluated on lambda creation not execution.