mirror of
git://git.musl-libc.org/musl
synced 2025-03-06 20:48:29 +01:00
fix regression in pthread_exit
commitd26e0774a5
moved the detach state transition at exit before the thread list lock was taken. this inadvertently allowed pthread_join to race to take the thread list lock first, and proceed with unmapping of the exiting thread's memory. we could fix this by just revering the offending commit and instead performing __vm_wait unconditionally before taking the thread list lock, but that may be costly. instead, bring back the old DT_EXITING vs DT_EXITED state distinction that was removed in commit8f11e6127f
, and don't transition to DT_EXITED (a value of 0, which is what pthread_join waits for) until after the lock has been taken.
This commit is contained in:
parent
3ab2a4e026
commit
debbddf7c8
2 changed files with 3 additions and 1 deletions
|
@ -68,7 +68,8 @@ struct pthread {
|
|||
};
|
||||
|
||||
enum {
|
||||
DT_EXITING = 0,
|
||||
DT_EXITED = 0,
|
||||
DT_EXITING,
|
||||
DT_JOINABLE,
|
||||
DT_DETACHED,
|
||||
};
|
||||
|
|
|
@ -156,6 +156,7 @@ _Noreturn void __pthread_exit(void *result)
|
|||
}
|
||||
|
||||
/* Wake any joiner. */
|
||||
a_store(&self->detach_state, DT_EXITED);
|
||||
__wake(&self->detach_state, 1, 1);
|
||||
|
||||
/* After the kernel thread exits, its tid may be reused. Clear it
|
||||
|
|
Loading…
Add table
Reference in a new issue