The code was able to use pthread destructors rather than C++ thread local destructors. This removes the dependence on a C++ .so on linux. However, this is not stable on other platforms such as Apple. Where the C++ thread local state can be cleared before the pthread destructor runs.