#include <userver/compiler/thread_local.hpp>
Creates a unique thread-local variable that can be used in a coroutine-safe manner.
Thread-local variables are known to cause issues when used together with userver coroutines:
Thread-local variables created through this class are protected against these issues.
ThreadLocal should be passed a factory function that constructs the variable. Example usage:
An example with slightly more complex initialization for the variable:
Once acquired through Use, the reference to the thread-local variable should not be returned or otherwise escape the scope of the ThreadLocalScope object. An example of buggy code:
Do not store a reference to the thread-local object in a separate variable:
Until the variable name goes out of scope, userver engine synchronization primitives and clients (web or db) should not be used.
Definition at line 128 of file thread_local.hpp.
Public Member Functions | |
| consteval | ThreadLocal (Factory factory) |
| ThreadLocalScope< VariableType > | Use () |
|
inlineconsteval |
Definition at line 133 of file thread_local.hpp.
|
inlineconsteval |
Definition at line 137 of file thread_local.hpp.
|
inline |
Definition at line 141 of file thread_local.hpp.