提交 59f88d76 编写于 作者: R Rich Felker

fix data race choosing next key slot in pthread_key_create

commit 84d061d5 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.
上级 8f12c4e1
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册