If non-parser parts of libxml (e.g. xmlwriter) are used before a parser, xmlOnceInit may have run (e.g. via the many paths to xmlGetGlobalState), but not xmlInitThreads (which is called only by xmlInitParser)
Once globalkey != TLS_OUT_OF_INDEXES (which can happen in many ways), DLLMAIN(DLL_THREAD_DETACH) may attempt to lock cleanup_helpers_cs before it is valid. This may happen even if the thread whose exit is triggering DllMain is from code which is not linked to libxml.
globalkey and cleanup_helpers_cs should be initialized together, with cleanup_helpers_cs initialized first and deleted last.