0.13.2 --- a thread created from C++ is the thread that is joined - #31
Merged
Conversation
musl's C++ pthread_t was unsigned long, thirty-two bits on LLP64 Windows, so a C++ program kept half of the thread's address and pthread_join faulted through it; every std::thread there ended in an access violation. The declaration now uses _Addr, which is long on every other target. examples/threads-cxx asserts the width at compile time and joins a thread on every CI row.
This was referenced Sep 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every
std::threadon Windows ended in an access violation when it was joined.musl declares
pthread_ttwice — a pointer for C,unsigned longfor C++ — andthe two agree wherever a
longholds a pointer. Windows is LLP64, so C++ codeabove this library kept the lower half of the thread's address. libc++ stores
pthread_tinstd::thread, andpthread_joinread through the truncated value:On windows-2022 the same programs exit with
0xC0000005. Found throughlsp-mcpp's unit tests, whose thread and process tests crashed only on Windows.
musl/include/alltypes.h.inand the five generatedalltypes.h: C++pthread_tisunsigned _Addr._Addris what musl already uses forsize_tand
uintptr_t; it islongon x86_64, aarch64 and riscv64, so nothingchanges there, and
long longonx86_64-windows.musl/PATCHES.mdrecords it as the fifth patched line, the same kind as theother four: a machine word carried through a
long.examples/threads-cxxasserts the width withstatic_assert(it does notcompile for
x86_64-windows-gnubefore this change) and creates and joins athread; CI runs it on every row.
Measured locally: the example fails to compile for
x86_64-windows-gnubeforethe change; after it, the Windows build prints
joined: 0, value 42, result is the argumentunder Wine. With openkal-llvm-runtime pointed at this tree,std::thread,a condition variable across threads and an exception thrown and caught inside a
thread all work under Wine.
0.13.2. Correction after merge: openkal-llvm-runtime pins
openkal-musl = "0.13.1"exactly (a consumer asking for 0.13.2 beside it is refused as irreconcilable), so
consumers reach this fix through openkal-llvm-runtime 0.9.3
(mcpplibs/openkal-llvm-runtime#18).