summaryrefslogtreecommitdiff
path: root/src/thread/pthread_key_delete.c
AgeCommit message (Collapse)AuthorLines
2019-02-16rewrite pthread_key_delete to use global thread listRich Felker-14/+0
with the availability of the thread list, there is no need to mark tsd key slots dirty and clean them up only when a free slot can't be found. instead, directly iterate threads and clear any value associated with the key being deleted. no synchronization is necessary for the clearing, since there is no way the slot can be accessed without having synchronized with the creation of a new key occupying the same slot, which is already sequenced after and synchronized with the deletion of the old key.
2018-09-18fix deletion of pthread tsd keys that still have non-null values storedRich Felker-0/+14
per POSIX, deletion of a key for which some threads still have values stored is permitted, and newly created keys must initially hold the null value in all threads. these properties were not met by our implementation; if a key was deleted with values left and a new key was created in the same slot, the old values were still visible. moreover, due to lack of any synchronization in pthread_key_delete, there was a TOCTOU race whereby a concurrent pthread_exit could attempt to call a null destructor pointer for the newly orphaned value. this commit introduces a solution based on __synccall, stopping the world to zero out the values for deleted keys, but only does so lazily when all key slots have been exhausted. pthread_key_delete is split off into a separate translation unit so that static-linked programs which only create keys but never delete them will not pull in the __synccall machinery. a global rwlock is added to synchronize creation and deletion of keys with dtor execution. since the dtor execution loop now has to release and retake the lock around its call to each dtor, checks are made not to call the nodtor dummy function for keys which lack a dtor.
2011-04-03simplify pthread tsd key handlingRich Felker-7/+0
2011-03-31simplify pthread_key_deleteRich Felker-1/+1
calling this function on an uninitialized key value is UB, so there is no need to check that the table pointer was initialized.
2011-02-12initial check-in, version 0.5.0v0.5.0Rich Felker-0/+7