http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54129
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-07-30 20:50:21 UTC --- >Where is the code in the destructor for the __thread variables? in libgcc/emutls.c . The code is: static void emutls_destroy (void *ptr) { struct __emutls_array *arr = ptr; pointer size = arr->size; pointer i; for (i = 0; i < size; ++i) { if (arr->data[i]) free (arr->data[i][-1]); } free (ptr); } static void emutls_init (void) { #ifndef __GTHREAD_MUTEX_INIT __GTHREAD_MUTEX_INIT_FUNCTION (&emutls_mutex); #endif if (__gthread_key_create (&emutls_key, emutls_destroy) != 0) abort (); } --- CUT ---- So it does is free the current thread memory. __gthread_key_create is a simple wrapper around pthread_key_create.