Thread specific storage APIs
Thread specific storage is used by your threaded application when you need global storage that is `private' to a thread. The storage is allocated and stored by the thread, and can be associated with a destructor function. When the thread ends using one of the pthread mechanisms, the destructor function runs and cleans up the thread local storage. The thread specific storage can replace global storage, because any function in a thread that requests the thread specific storage will get the same value. Functions in another thread that request the thread specific storage will get the thread specific storage owned by the thread that they are called in.
For information about the examples included with the APIs, see Information about the Pthread API examples.
The thread specific storage APIs are:
- pthread_getspecific() (Get Thread Local Storage Value by Key) retrieves the thread local storage value associated with the key. pthread_getspecific() may be called from a data destructor.
- pthread_key_create() (Create Thread Local Storage Key) creates a thread local storage key for the process and associates the destructor function with that key.
- pthread_key_delete() (Delete Thread Local Storage Key) deletes a process-wide thread local storage key.
- pthread_setspecific() (Set Thread Local Storage by Key) sets the thread local storage value associated with a key.
[ Back to top | Pthread APIs | APIs by category ]