Repository navigation
Conversation
Contributor
sbc100
reviewed
Oct 22, 2026
sbc100
reviewed
Oct 22, 2026
sbc100
reviewed
Oct 22, 2026
sbc100
reviewed
Oct 22, 2026
typedrat
force-pushed
the
typedrat/pthread-finished-mark-reused
branch
from
October 23, 2026 20:18
e20a4dd to
f6612c0
Compare
…n dlopen sync With dynamic linking, a joinable thread posts CMD_MARK_AS_FINISHED to the main thread as it exits, so that dlopen()'s sync skips it. A join cleans the thread up as soon as it returns, possibly before that message is handled, and a new thread created in the meantime can get the same pthread_t. The late message then marked the new, running thread as finished, so every later dlopen() skipped it and its calls into newly loaded modules trapped. Only mark a thread if it is still known and has actually exited. Fixes: emscripten-core#27841
typedrat
force-pushed
the
typedrat/pthread-finished-mark-reused
branch
from
October 23, 2026 20:24
f6612c0 to
cf37052
Compare
This branch has not been deployed
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.
With dynamic linking, a joinable thread posts
CMD_MARK_AS_FINISHEDto the main thread as it exits, so thatdlopen()'s sync skips it. But a join cleans the thread up as soon as it returns, possibly before that message is handled, and a new thread created in the meantime can get the samepthread_t. The late message then marks the new, running thread as finished, so laterdlopen()calls skip it, and its calls into newly loaded modules trap with "table index is out of bounds".The fix only marks a thread if it is still known and has actually exited (
detach_stateisDT_EXITINGorDT_EXITED). The check lives inmarkAsFinished, which readsdetach_statedirectly viaC_STRUCTS.pthread.Test:
core.test_pthread_dlsync_reusedjoins a thread on the main thread, creates another one that reuses itspthread_t, thendlopen()s a side module and calls into it from the new thread. It fails onmainwith the trap and passes with the fix, incore0–core3andwasm64. It assumes the stale message is handled within the 100 ms beforedlopen(); if it weren't, the test could pass without the fix, but it can't fail with it.Fixes: #27841