Linker and Libraries Guide

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 may be allocated separately, or as a single contiguous block.

Each thread t has an associated thread pointer tpt, which points to the thread control block, TCB. The thread pointer, tp, always contains the value of tpt for the current running thread.

The thread library then creates a vector of pointers, dtvt, for the current thread t. The first element of each vector contains a generation number gent, which is used to determine when the vector needs to be extended. See Deferred Allocation of Thread-Local Storage Blocks.

Each remaining element in the vector, dtvt,m, is a pointer to the block reserved for the TLS belonging to dynamic object m.

For dynamically loaded, post-startup objects, the thread library defers the allocation of TLS blocks. This allocation occurs when the first reference is made to a TLS variable within the loaded object. All references to TLS defined in a post-startup, dynamically loaded object, must use a dynamic TLS model. For blocks whose allocation has been deferred, the pointer dtvt,m is set to an implementation-defined special value.


Note –

The runtime linker may group TLS templates for all startup objects such that they share a single element in the vector, dtvt,1. This does not affect the offset calculations described above 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.