Thread Creation
For the initial thread, and for each new thread created, the thread library allocates a new TLS block for each loaded dynamic object. Blocks can be allocated separately, or as a single contiguous block.
Each thread t, has an associated thread pointer
tp
t, which points
to the thread control block, TCB
. The thread
pointer, tp
, always contains the value of
tp
t for the
current running thread.
The thread library then creates a vector of pointers,
dtv
t, for the
current thread t
. The first element of each
vector contains a generation number
gen
t, which is
used to determine when the vector needs to be extended. See Deferred Allocation of Thread-Local Storage Blocks.
Each element remaining in the vector
dtv
t,m, is a
pointer to the block that is reserved for the TLS
belonging to the dynamic object m
.
For dynamically loaded, post-startup objects, the thread library
defers the allocation of TLS blocks. Allocation
occurs when the first reference is made to a TLS
variable within the loaded object. For blocks whose allocation has
been deferred, the pointer
dtv
t,m is set to
an implementation-defined special value.
Note:
The runtime linker can group TLS templates for all startup objects so as to share a single element in the vector,dtv
t,1. This grouping does not affect
the offset calculations described previously or the creation
of the list of initialization records. For the following
sections, however, the value of M
, the
total number of objects, start with the value of 1.
The thread library then copies the initialization images to the corresponding locations within the new block of storage.