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

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 2 11:36:33 PDT 2016


EricWF added inline comments.

================
Comment at: src/cxa_thread_atexit.cpp:42
@@ +41,3 @@
+  // - thread_local destructors on other threads run on the first iteration
+  //   through the pthread_key destructors.  std::notify_all_at_thread_exit()
+  //   and similar functions must be careful to wait until the second iteration
----------------
tavianator wrote:
> EricWF wrote:
> > Can you clarify what you mean by "other threads"?
> > 
> > How is libc++ supposed to detect and handle this problem? 
> I meant "non-main threads" ("other" is in relation to the bullet point above), but I can clarify this, sure.
> 
> libc++ could be patched to do something like this:
> 
> ```
> pthread_key_t key1, key2;
> 
> void destructor1(void* ptr) {
>   pthread_setspecific(key2, ptr);
> }
> 
> void destructor2(void* ptr) {
>   // Runs in the second iteration through pthread_key destructors,
>   // therefore after thread_local destructors
> }
> 
> pthread_key_create(&key1, destructor1);
> pthread_key_create(&key2, destructor2);
> 
> pthread_setspecific(key1, ptr);
> ```
> 
> (Or it could use a counter/flag and a single pthread_key.)
> 
> libstdc++ has the same bug when __cxa_thread_atexit_impl() isn't available, so I'm not sure that change would really be necessary.  If it is, I can write up the libc++ patch.
I don't think we need to patch this in libc++. Especially because it would be incorrect in the vast majority of cases.


https://reviews.llvm.org/D21803





More information about the cfe-commits mailing list