. . .
TSD is typically used to declare all the keys globally, initialize (er, "create") them in main(),
then create threads and start the program for real. If you are creating some TSD in a library, you
must arrange for that library to do the initialization before use. In Code Example 8-1, bar() in
,[2].and in the second thread will see š
the first thread will see
One of my best friends, a math wizz, purchased a small farm in rural Minnesota. His address was
1414, rural route 2
Example 8-1 Use of POSIX TSD
pthread_key_t house_key;
foo((void *) arg) {
pthread_setspecific(house_key, arg);
bar() {
float n;
n = (float) pthread_getspecific(house_key);
main() {
pthread_keycreate(&house_key, NULL);
pthread_create(&tid, NULL, foo, (void *) 1.414);
pthread_create(&tid, NULL, foo, (void *) 3.141592653589);
In Win32 there is a different version of TSD. Win32 calls it dynamic thread local storage and its
use is virtually identical to TSD in POSIX (Code Example 8-2). Other than the lack of destructors,
you may use it in the same fashion as TSD.
Example 8-2 Dynamic TLS in Win32
Search WWH :
Custom Search
Previous Page
Multithreaded Programming with JAVA - Topic Index
Next Page
Multithreaded Programming with JAVA - Bookmarks