This is the mail archive of the
mailing list for the pthreas-win32 project.
When is the pthread_key_create destructor called?
- From: "Brian Cole" <coleb2 at gmail dot com>
- To: pthreads-win32 at sourceware dot org
- Date: Sat, 22 Mar 2008 09:12:44 -0600
- Subject: When is the pthread_key_create destructor called?
Is it safe to assume that when a thread exits its destructor functions
for thread specific values have finished executing before the thread
can be joined?
For example, is the following free of race conditions?
static pthread_key_t key;
void dtor(void *val)
// safely push the data pointed to by val into some global data structure
void *thread_func(void *)
pthread_setspecific(key, //pointer to some data that will be pushed
into a global data structure on exit);
pthread_exit(NULL); // What happens if I don't call this and let it
run off the end of the function?
pthread_create(&thrd, NULL, thread_func, NULL);
// safe to assume data that was in thread local storage is all in my
global data structure?
If this is not the case, would adding a pthread_key_delete achieve the
desired behavior? And further, how cross-platform is this behavior
seeing as I can't find it explicitly stated in any pthreads
To further complicate the matter my threads are actually OpenMP
threads. Is it safe to assume they will properly clean up thread
specific data in the same semantic fashion?