Make POSIX threads improvements

- Ensure SIGTHR isn't blocked in newly created threads
- Use TIB rather than thread_local for thread atexits
- Make POSIX thread keys atomic within thread
- Don't bother logging prctl() to --strace
- Log thread destructor names to --strace
This commit is contained in:
Justine Tunney 2024-06-30 15:38:59 -07:00
parent 387310c659
commit 76957983cf
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
11 changed files with 57 additions and 71 deletions

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/errno.h"
#include "libc/intrin/atomic.h"
#include "libc/thread/posixthread.internal.h"
@ -32,10 +31,12 @@
*
* @param key was created by pthread_key_create()
* @return 0 on success, or errno on error
* @raise EINVAL if `key` is invalid
*/
int pthread_key_delete(pthread_key_t k) {
unassert(0 <= k && k < PTHREAD_KEYS_MAX);
unassert(atomic_load_explicit(_pthread_key_dtor + k, memory_order_acquire));
atomic_store_explicit(_pthread_key_dtor + k, 0, memory_order_release);
if (!(0 <= k && k < PTHREAD_KEYS_MAX))
return EINVAL; // corrupt key identifier
if (!atomic_exchange_explicit(&_pthread_key_dtor[k], 0, memory_order_acq_rel))
return EINVAL; // delete called twice
return 0;
}