ThreadLocalStorage
[Threading]

Collaboration diagram for ThreadLocalStorage:


Data Structures

class  ThreadLocal< T >

Typedefs

typedef void(*) ThreadLocalDtor (void *)
 A pointer to a function used to free a piece of thread local storage.
typedef size_t TLSKey
 A key used to access thread local storage.

Functions

LDK_TLS_API TLSKey threadLocalCreateKey (ThreadLocalDtor dtor=NULL)
 Create a key for thread local storage.
LDK_TLS_API void threadLocalSet (TLSKey key, void *object)
 Associate an object with a key for the current thread.
LDK_TLS_API void * threadLocalGet (TLSKey key)
 Get the object associated with key for the current thread.

Detailed Description

Programs often need global or static variables that have different values in different threads. Since threads share one memory space, this cannot be achieved with regular variables. Thread local storage is the answer to this need.

Each thread possesses a private memory block, the thread-local data area (TLD). This area is indexed by TLS keys. The TLD area associates values of type void * to TLS keys. TLS keys are common to all threads, but the value associated with a given TLS key can be different in each thread.

For concreteness, the TLS areas can be viewed as arrays of void * pointers, TLS keys as integer indices into these arrays, and the value of a TLS key as the value of the corresponding array element in the calling thread.

When a thread is created, its TLS area initially associates NULL with all keys. This behavior is undocumented on MS Windows.

This description was adapted from the pthread_key_create GNU-Linux manpage.


Function Documentation

TLSKey threadLocalCreateKey ( ThreadLocalDtor  dtor = NULL  ) 

Parameters:
dtor A pointer to a function to free a piece of thread local storage.
Returns:
A unique key to be used with threadLocalSet() and threadLocalGet().

Referenced by LDK::GenericXmlBinding< const char * >::GenericXmlBinding(), LDK::TLSSingletonStorage< T >::initialise(), and ThreadLocal< T >::ThreadLocal().

void * threadLocalGet ( TLSKey  key  ) 

Parameters:
key The unique identifier associated with an object in the current thread.
Returns:
NULL if there is nothing associated with a key in the current thread, otherwise the associated object.

Referenced by LDK::GenericXmlBinding< const char * >::fromXml(), LDK::TLSSingletonStorage< T >::instance(), ThreadLocal< T >::operator &(), and ThreadLocal< T >::operator->().

void threadLocalSet ( TLSKey  key,
void *  object 
)

Parameters:
key The unique identifier associated with an object in the current thread.
object The object to associate with key in the current thread.

Referenced by LDK::GenericXmlBinding< const char * >::fromXml(), LDK::TLSSingletonStorage< T >::instance(), ThreadLocal< T >::operator &(), and ThreadLocal< T >::operator->().


Generated on Fri Aug 17 18:32:27 2007 for LDK by  doxygen 1.5.1