Thread local
Thread-local data is data whose value or instance is independently associated with each executing thread.
Grokking Software Architecture
A variable whose value is maintained separately for each thread of execution.
- How it is used
- Uses thread-local context to enrich application logs with request metadata without adding telemetry parameters to business methods.
- How deep it goes
- Defines per-thread isolation and traces MDC metadata through logging and cleanup, but does not detail runtime implementation internals.
- Examples
- Uses tenantId and orderId metadata, checkout logs, and a test that checks context at a service boundary.
- What you can do after
- Apply MDC to attach transaction identifiers to logs and remove the context when the operation ends.
Read how Grokking Software Architecture explains thread local →
Modern C
Thread-local data is data whose storage is separately associated with each executing thread.
- How it is used
- Separates per-thread state to avoid race-prone shared access, while favoring function arguments and local variables first.
- How deep it goes
- Explains separate instances, declaration scope, compile-time initialization, and dynamic-storage alternatives, but not a complete concurrent program.
- Examples
- Uses _Thread_local, thread_local, tss_t, tss_get, tss_set, tss_create, tss_delete, and destructor callbacks as interface examples.
- What you can do after
- Apply via C's thread_local or tss interfaces to maintain state separately for each thread.
Also covered in
- Quarkus in Action
- Idiomatic Rust
- Python Concurrency with asyncio
- The Well-Grounded Rubyist, Fourth Edition
- Modern C, Third Edition
- Spring Security in Action, Second Edition
- Learn Rust in a Month of Lunches
- BDD in Action, Second Edition
- C# Concurrency: Asynchronous and multithreaded programming
What to know first
- threadA thread is an execution sequence or context within a program or process that represents a unit of work and can run or be scheduled independently of other threads.
- race conditionA race condition is a concurrency defect in which program behavior or results depend on the timing or ordering of interacting operations.
- command-line argumentA command-line argument is a value or option supplied to a program when it is invoked, providing input or affecting its behavior.
- lockingLocking is a synchronization technique that restricts concurrent access to a shared resource or protected operation.
Related concepts
- storage classkind of · A storage class specifier is a C declaration keyword that specifies an object's storage duration, linkage, or related declaration properties.
- mapped diagnostic contextused by · A mapped diagnostic context is a set of key-value data associated with an execution context so logging systems can include that information in log records.
- security contextused by · A security context is security-related configuration or execution state associated with a subject, request, container, or runtime environment.
- context variablecontrasts with · A context variable is a value associated with a particular execution or situation that provides context for processing or interpreting an operation.
- global variablekind of · A global variable is a variable whose binding is accessible from broad program or module scopes according to the language’s name-resolution rules.
Questions about thread local
What is thread local?
Thread-local data is data whose value or instance is independently associated with each executing thread.
Which Manning books explain thread local?
Grokking Software Architecture and Modern C.
What should I know before learning thread local?
Manning books that teach thread local usually introduce thread, race condition, command-line argument and locking first.
What is the difference between thread local and context variable?
Thread-local data is data whose value or instance is independently associated with each executing thread. A context variable is a value associated with a particular execution or situation that provides context for processing or interpreting an operation.
What is thread local a kind of?
Thread local is a kind of storage class. A storage class specifier is a C declaration keyword that specifies an object's storage duration, linkage, or related declaration properties.
What is thread local also called?
Thread local is also called ThreadLocal.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

