Thread-Specific Data
in Pthreads |
Prof. David Bernstein
|
Computer Science Department |
bernstdh@jmu.edu |
int pthread_key_create(pthread_key_t *key, void (*destructor)(void *)
key
|
A key that can be used to obtain thread-specific data |
destructor
|
The function to call to free the thread-specific memory (or NULL if no destructor is needed) |
Return | 0 on success; a positive error number on error |
Note: destructor()
will be invoked automatically by the
system when the thread terminates (and passed the address of the
thread-specific memory for this key
).
int pthread_setspecific(pthread_key_t key, const void *value)
key
|
The key used to identify the thread-specific data |
value
|
The value to save (which is normally a block of memory that has been previously allocated by the caller) |
Return | 0 on success; a positive error number on error |
A Driver with a Single Thread
unixexamples/threadspecificdata/driver.cA Driver with Multiple Threads
unixexamples/threadspecificdata/threaded_driver.c