diff options
author | Rich Felker <dalias@aerifal.cx> | 2019-03-21 13:58:12 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2019-03-21 13:58:12 -0400 |
commit | 59f88d766263344ce3e124d969ba66720aff4590 (patch) | |
tree | 1d7c438347cc69a5e865d404b3b339f74e144044 /src | |
parent | 8f12c4e110acb3bbbdc8abfb3a552c3ced718039 (diff) | |
download | musl-59f88d766263344ce3e124d969ba66720aff4590.tar.gz musl-59f88d766263344ce3e124d969ba66720aff4590.tar.bz2 musl-59f88d766263344ce3e124d969ba66720aff4590.tar.xz musl-59f88d766263344ce3e124d969ba66720aff4590.zip |
fix data race choosing next key slot in pthread_key_create
commit 84d061d5a31c9c773e29e1e2b1ffe8cb9557bc58 wrongly moved the
access to the global next_key outside of the scope of the lock. the
error manifested as spurious failure to find an available key slot
under concurrent calls to pthread_key_create, since the stopping
condition could be met after only a small number of slots were
examined.
Diffstat (limited to 'src')
-rw-r--r-- | src/thread/pthread_key_create.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/thread/pthread_key_create.c b/src/thread/pthread_key_create.c index 210605c6..d1120941 100644 --- a/src/thread/pthread_key_create.c +++ b/src/thread/pthread_key_create.c @@ -22,7 +22,6 @@ weak_alias(dummy_0, __tl_unlock); int __pthread_key_create(pthread_key_t *k, void (*dtor)(void *)) { - pthread_key_t j = next_key; pthread_t self = __pthread_self(); /* This can only happen in the main thread before @@ -33,6 +32,7 @@ int __pthread_key_create(pthread_key_t *k, void (*dtor)(void *)) if (!dtor) dtor = nodtor; __pthread_rwlock_wrlock(&key_lock); + pthread_key_t j = next_key; do { if (!keys[j]) { keys[next_key = *k = j] = dtor; |