liveBook · Manning

Thread local

Also called ThreadLocal

Thread-local data is data whose value or instance is independently associated with each executing thread.

How 2 Manning books explain it

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.

Read how Modern C explains thread local →

Also covered in

What to know first

Related concepts

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.