For example, I have a thread_local variable in my code, but there are a set of functions, which access and modify it. For modularity, I took out them to a different translation unit (correct me if I'm wrong on terminology), by creating a header with their declarations and source file with their definitions.
// fun.h int fun(); // fun.cpp #include "fun.h" int fun() { // Modify the thread_local variable here } // main.cpp #include "fun.h" thread_local int var = 0; int main() { // Modify the var in the main var = 1; // Modify the var by calling the fun() from fun.h fun(); } What to do? How to access it from fun()? Isn't there a contradiction that global variables are common for all the threads of the process, but thread_local is local?
externin the translation unit that wants to access it. That is commonly done using a header file, but that is not strictly a requirement.