- Eingeführt in: C++11
thread_local varType varName; thread_local unsigned int counter; thread_local std::string s = "getting schwifty"; ...
thread_local Entities have thread storage duration. This mean that every single thread in a program has its own copy of its
thread_local Entities are implicit static and get destroyed upon thread exit.
The best way to avoid data races is not sharing the data between threads. By using
thread_local variables, each thread will have its own copy of the data, and this data can only be written or reading by its own thread.