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.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix races around pthread exit and join #409
Fix races around pthread exit and join #409
Changes from 1 commit
99db501
7262ca4
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we instead call
__tl_unlock
right beforea_store(&self->detach_state, DT_EXITED);
like we do right befree(self->map_base);
?In the first case we are unlocking right before notifying the joiner that they can call free and in the later case we are unlocking right before we call
free
ourselves, so it seem symmetrical.(I'm suggesting this so that we can avoid re-implementing
__tl_unlock
in asm if we can).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, what was wrong with the single
__tl_unlock
on line 172 that we had previously?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this PR doesn't re-implement
__tl_unlock
.it emulates
CLONE_CHILD_CLEARTID
, which the__tl_lock/unlock/sync
protocol relies on.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree the double unlock thing looks like a bug.
But the joiner is not waiting on the
tl_lock
is it? The joiner seems to be waiting ont->detach_state
. In fact, I don't see thetl_lock
referenced at all inpthread_join.c
. Maybe I'm missing something?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the joiner uses
__td_sync
to sync with the exit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about putting all this new code a new local function called
__tl_unlock_asm
? And perhaps mention in the comment why we need to asm re-implementation here.Otherwise this lgtm now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i added a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading over the definition of
__tl_unlock
it additionally decrementstl_lock_count
. It might be good to assert that is zero in C before returning here to perform this. Additionally it might be good to leave a comment in__tl_unlock
that this needs updating if the implementation changes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just
call __tl_unlock
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i feel it belongs to upstream musl, not here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because
__tl_unlock
is a C function, which potentially requires C stack.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean by it belongs in upstream musl? Wasi-libc is already patching musl a fair bit, so what I'm saying is that as part of the patching the cases where
__pthread_exit
returns should all assert that thetl_lock_count
is zero.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i meant tl_lock_count should be zero when a thread exits is not wasi-specific.
if you feel strongly i can add such an assertion.