From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25342 invoked by alias); 22 Mar 2008 15:13:04 -0000 Received: (qmail 25332 invoked by uid 22791); 22 Mar 2008 15:13:03 -0000 X-Spam-Check-By: sourceware.org Received: from rv-out-0910.google.com (HELO rv-out-0910.google.com) (209.85.198.191) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 22 Mar 2008 15:12:46 +0000 Received: by rv-out-0910.google.com with SMTP id l15so938269rvb.48 for ; Sat, 22 Mar 2008 08:12:44 -0700 (PDT) Received: by 10.141.133.14 with SMTP id k14mr1735174rvn.127.1206198764773; Sat, 22 Mar 2008 08:12:44 -0700 (PDT) Received: by 10.141.40.10 with HTTP; Sat, 22 Mar 2008 08:12:44 -0700 (PDT) Message-ID: <54b165660803220812h8ead035jb908f750a85e1caa@mail.gmail.com> Date: Sat, 22 Mar 2008 15:13:00 -0000 From: "Brian Cole" To: pthreads-win32@sourceware.org Subject: When is the pthread_key_create destructor called? MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-IsSubscribed: yes Mailing-List: contact pthreads-win32-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sourceware.org X-SW-Source: 2008/txt/msg00007.txt.bz2 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 documentation. 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? Thanks, Brian