2.9. Thread-local storage

Thread-Local Storage (TLS) is a class of static storage that, like the stack, exists only once for each thread of execution. Each thread in a process is given a location where it can store thread-specific data. Variables are allocated such that there is one instance of the variable for each existing thread.

A global index is used to provide unique data for each thread that the process can access. One thread allocates the index when the process starts. This is then used by the other threads to retrieve the unique data associated with the index. When a thread starts, it allocates a block of dynamic memory and stores a TLS pointer to this memory. In general, TLS pointers point to a specific memory location, returned by a library function. This is a CP15 register on ARM MPCore™.

Before each thread terminates, it releases its dynamic memory and any pointers to thread-local variables in that thread become invalid. Before the process terminates, it releases the index.

See __declspec(thread) in the Compiler Reference Guide for more information.

Copyright © 2002-2007 ARM Limited. All rights reserved.ARM DUI 0205H