×
Namespaces

Variants
Actions

POSIX TLS

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: spark55 (07 Sep 2007)
Last edited: hamishwillee (27 Jul 2012)

Contents

POSIX TLS

TLS(Thread Specific Data or Thread Local Storage) is memory area that is specific to that particular thread.Any kind of DLL or exe can use this.

TLS is provided in chunks of 4 bytes. Each such 4 bytes of chunk is called a key. If a program needs TLS, then it has to create a key. Once a key is created, an ID (handle) is returned. And this ID should be used to read and write to the key.

The following APIs which are part of libpthread describes briefly how to create,read,write and free a key.

Creating a key

The pthread_key_create() API creates a new key and returns the ID.


Reading from a key

The pthread_getspecific() API can be used to read the value of the key. Here, it takes the ID of the key as an argument.


Writing to a key

pthread_setspecific() API can be used to set the value to a key. It takes the ID of the key as argument.


Freeing the key

The pthread_key_delete() API deletes the key in all the threads. Once the key is deleted, no thread should use the old handle/ID to set and get the key value.


If a thread is created after the key is created, then the key is available in the new thread from the beginning.


Links

This page was last modified on 27 July 2012, at 05:16.
34 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×