[PATCH] D21803: [libcxxabi] Provide a fallback __cxa_thread_atexit() implementation

Ben Craig via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 30 06:44:09 PDT 2016

bcraig added a comment.

In http://reviews.llvm.org/D21803#470564, @joerg wrote:

> On the topic of __cxa_thread_atexit, was it ever specified how it interacts with things like thread cancellation?

I don't think it's officially specified anywhere.  C++ threads don't have a cancel method.  The POSIX spec doesn't speak about the C++ ABI.  The Itanium ABI could talk about this, but hasn't yet.

I think this implementation does the right thing with regards to cancellation though.  POSIX says that first cancellation cleanup handlers are called, then thread-specific data destructors are called.  pthread_cancel is still a really bad idea due to how it (doesn't) interact with RAII, but at least TLS data won't get leaked.

Comment at: src/cxa_thread_atexit.cpp:46
@@ +45,3 @@
+      pthread_key_delete(key_);
+    }
dimitry wrote:
> run_dtors() is called when/if libc++.so gets unloaded... but only for the thread calling dlclose()?
Most of the dtor magic is on the pthread_key_create side.  pthreads lets you register a per-thread destructor.

This destructor is only run on process termination (I think).


More information about the cfe-commits mailing list