I want to do some work after all C++ thread_local destructors called.
This is platform specific - Android, so I have access to pthreads
.
The question is, when pthread_key_create
d destructors should be called, before or after C++ thread_local
destructors? Or they can be interleaved?
I tested On Linux Mint and pthread destructors called after C++ 's.
bionic/pthread_exit.cpp currently has the same order:
void pthread_exit(void* return_value) {
// Call dtors for thread_local objects first.
__cxa_thread_finalize();
// Call the TLS destructors.
pthread_key_clean_all();
However, this is not documented behavior and you should not build something relying on it.