diff options
author | Pino Toscano <toscano.pino@tiscali.it> | 2011-11-02 17:38:46 +0100 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2011-11-05 21:26:10 +0100 |
commit | ea6390b2f20a03b7d504bc68a1c95e645d271149 (patch) | |
tree | 67b20f547c20978a58528f2fcd59466256d83fd6 /sysdeps | |
parent | 081c7aeb4d4de82ab615db565c60dd776a385c34 (diff) |
Remove all the values when deleting a key
When deleting a key using `pthread_key_delete', delete all the values
associated to that key in all the threads available. Otherwise, the
key reuse in `pthread_key_create' can cause new keys to have thread
specific data of the previously used key with the same index.
Add a test for this case, which creates and deletes pairs of keys
checking that they have a NULL thread specific data after creation.
* sysdeps/hurd/pt-key-delete.c (pthread_key_delete): Remove all the
values of the key in all the threads.
* tests/Makefile (CHECK_SRC): Add test-17.c.
* tests/test-17.c: New file.
Diffstat (limited to 'sysdeps')
-rw-r--r-- | sysdeps/hurd/pt-key-delete.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/sysdeps/hurd/pt-key-delete.c b/sysdeps/hurd/pt-key-delete.c index 2426bb1..9d88647 100644 --- a/sysdeps/hurd/pt-key-delete.c +++ b/sysdeps/hurd/pt-key-delete.c @@ -35,8 +35,27 @@ pthread_key_delete (pthread_key_t key) err = EINVAL; else { + int i; + __pthread_key_destructors[key] = PTHREAD_KEY_INVALID; __pthread_key_invalid_count ++; + + pthread_rwlock_rdlock (&__pthread_threads_lock); + for (i = 0; i < __pthread_num_threads; ++i) + { + struct __pthread *t; + + t = __pthread_threads[i]; + + if (t == NULL) + continue; + + /* Just remove the key, no need to care whether it was + already there. */ + if (t->thread_specifics) + hurd_ihash_remove (t->thread_specifics, key); + } + pthread_rwlock_unlock (&__pthread_threads_lock); } __pthread_mutex_unlock (&__pthread_key_lock); |