public inbox for
 help / color / mirror / Atom feed
From: "Brian Cole" <>
Subject: When is the pthread_key_create destructor called?
Date: Sat, 22 Mar 2008 15:13:00 -0000	[thread overview]
Message-ID: <> (raw)

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?

int main()
  pthread_key_create(key, dtor);

  pthread_t thrd;
  pthread_create(&thrd, NULL, thread_func, NULL);

  void *ret;
  pthread_join(thrd, &ret);

  // 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?


             reply	other threads:[~2008-03-22 15:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-22 15:13 Brian Cole [this message]
2008-03-23  1:51 ` Ross Johnson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).