mirror of
git://git.musl-libc.org/musl
synced 2025-03-07 04:07:30 +00:00
fix data race between new pthread_key_delete and dtor execution
access to clear the entry in each thread's tsd array for the key being deleted was not synchronized with __pthread_tsd_run_dtors. I probably made this mistake from a mistaken belief that the thread list lock was held during the latter, which of course is not possible since it executes application code in a still-live-thread context. while we're at it, expand the interval during which signals are blocked to cover taking the write lock on key_lock, so that a signal at an inopportune time doesn't block forward progress of readers.
This commit is contained in:
parent
639bcf251e
commit
805288929f
@ -51,15 +51,17 @@ int __pthread_key_delete(pthread_key_t k)
|
|||||||
pthread_t self = __pthread_self(), td=self;
|
pthread_t self = __pthread_self(), td=self;
|
||||||
|
|
||||||
__block_app_sigs(&set);
|
__block_app_sigs(&set);
|
||||||
|
__pthread_rwlock_wrlock(&key_lock);
|
||||||
|
|
||||||
__tl_lock();
|
__tl_lock();
|
||||||
do td->tsd[k] = 0;
|
do td->tsd[k] = 0;
|
||||||
while ((td=td->next)!=self);
|
while ((td=td->next)!=self);
|
||||||
__tl_unlock();
|
__tl_unlock();
|
||||||
__restore_sigs(&set);
|
|
||||||
|
|
||||||
__pthread_rwlock_wrlock(&key_lock);
|
|
||||||
keys[k] = 0;
|
keys[k] = 0;
|
||||||
|
|
||||||
__pthread_rwlock_unlock(&key_lock);
|
__pthread_rwlock_unlock(&key_lock);
|
||||||
|
__restore_sigs(&set);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user