[PATCH] Destructor support for C++11 thread_local variables

Roland McGrath roland@hack.frob.com
Wed Oct 10 23:20:00 GMT 2012


I really hope there will be a way to use this from C, e.g.

__thread type x;
static void __attribute__((thread_destructor (x))) foo (type *x_ptr) { ... }

I'm pretty disinclined to add features to libc whose only possible use
is via C++.

Who says preventing DSO unloading is the right semantics?  The obvious
analog to global destructors is to run them all on dlclose.  That's
difficult to do if the semantics are that the destructor runs on the
thread owning the variable.  (They'd be running inside a signal
handler or something scary like that.)  It's not so hard if the
destructor takes the specific object pointer as a parameter and might
run on any thread.  What is supposed to happen when you dlopen an
object defining thread_local variables with constructors when there
are already multiple threads?


Thanks,
Roland



More information about the Libc-alpha mailing list