Skip to content

Destroy thread_local objects before statics on msvcrt - #429

Open
skeeto wants to merge 1 commit into
masterfrom
thread-atexit
Open

skeeto wants to merge 1 commit into
masterfrom
thread-atexit

Conversation

@skeeto

@skeeto skeeto commented Oct 22, 2026

Copy link
Copy Markdown
Owner

The main thread's thread_local destructors must finish before any static destructor starts, but statics and atexit handlers registered after the first thread_local was constructed ran first, because cross builds of libstdc++ used their atexit-based fallback. Use the CRT's __cxa_thread_atexit instead. On msvcrt that is only correct with mingw-w64 a394c23a51, merged after v14.0.0, so backport it without its Makefile.am change. Tested on Windows 11 and XP, x64 and x86. One XP limitation is noted in the gcc patch header.

@Peter0x44, about msys2/MSYS2-packages#6872.

The main thread's thread_local destructors must finish before any
static destructor starts, but statics and atexit handlers registered
after the first thread_local was constructed ran first, because cross
builds of libstdc++ used their atexit-based fallback. Use the CRT's
__cxa_thread_atexit instead. On msvcrt that is only correct with
mingw-w64 a394c23a51, merged after v14.0.0, so backport it without its
Makefile.am change. Tested on Windows 11 and XP, x64 and x86. One XP
limitation is noted in the gcc patch header.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant