This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

pthread_key_delete() is broken.


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]