This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
pthread_key_delete() is broken.
- To: GNU C Library <libc-alpha at sourceware dot cygnus dot com>
- Subject: pthread_key_delete() is broken.
- From: Kaz Kylheku <kaz at ashi dot footprints dot net>
- Date: Mon, 12 Nov 2001 11:18:13 -0800 (PST)
Basically the problem is that it tries to set the value of the
key to NULL in every running thread. To do that, it iterates
over the threads. Doing that creates a race condition against
the thread manager, which owns this list.
One manifestation of the bug is that a simple program which spins
a thread, which in turn creates and then deletes a key, will
sometimes segfault!
The reason is that when the thread is already running, the manager has
not necessarily yet finished adding it to its list. So there is a race
between pthread_key_delete() trying to walk the list and the thread
manager updating the list.
My planned fix is this: introduce a new request type to the thread
manager: REQ_FOR_EACH_THREAD. This request will cause the thread
manager to iterate over all the threads and invoke a specified callback,
then unblock the requestor when it is done. It will be an interface
for any module that needs to safely walk the list of running threads and
take some action on each one, without introducing awkward dependencies
into the manager.