Drop self->pt_lock before clearing TSD / malloc TSD.

This commit is contained in:
ad 2020-06-11 18:42:02 +00:00
parent 2b4d53924f
commit 30140ed218
2 changed files with 7 additions and 11 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: pthread.c,v 1.175 2020/06/10 22:45:15 ad Exp $ */
/* $NetBSD: pthread.c,v 1.176 2020/06/11 18:42:02 ad Exp $ */
/*-
* Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pthread.c,v 1.175 2020/06/10 22:45:15 ad Exp $");
__RCSID("$NetBSD: pthread.c,v 1.176 2020/06/11 18:42:02 ad Exp $");
#define __EXPOSE_STACK 1
@ -615,21 +615,18 @@ pthread_exit(void *retval)
pthread_mutex_lock(&self->pt_lock);
self->pt_flags |= PT_FLAG_CS_DISABLED;
self->pt_cancel = 0;
pthread_mutex_unlock(&self->pt_lock);
/* Call any cancellation cleanup handlers */
if (!PTQ_EMPTY(&self->pt_cleanup_stack)) {
pthread_mutex_unlock(&self->pt_lock);
while (!PTQ_EMPTY(&self->pt_cleanup_stack)) {
cleanup = PTQ_FIRST(&self->pt_cleanup_stack);
PTQ_REMOVE(&self->pt_cleanup_stack, cleanup, ptc_next);
(*cleanup->ptc_cleanup)(cleanup->ptc_arg);
}
pthread_mutex_lock(&self->pt_lock);
}
pthread_mutex_unlock(&self->pt_lock);
__cxa_thread_run_atexit();
pthread_mutex_lock(&self->pt_lock);
/* Perform cleanup of thread-specific data */
pthread__destroy_tsd(self);
@ -641,6 +638,7 @@ pthread_exit(void *retval)
* Signal our exit. Our stack and pthread_t won't be reused until
* pthread_create() can see from kernel info that this LWP is gone.
*/
pthread_mutex_lock(&self->pt_lock);
self->pt_exitval = retval;
if (self->pt_flags & PT_FLAG_DETACHED) {
/* pthread__reap() will drop the lock. */

View File

@ -1,7 +1,7 @@
/* $NetBSD: pthread_tsd.c,v 1.22 2020/04/19 20:47:03 joerg Exp $ */
/* $NetBSD: pthread_tsd.c,v 1.23 2020/06/11 18:42:02 ad Exp $ */
/*-
* Copyright (c) 2001, 2007 The NetBSD Foundation, Inc.
* Copyright (c) 2001, 2007, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pthread_tsd.c,v 1.22 2020/04/19 20:47:03 joerg Exp $");
__RCSID("$NetBSD: pthread_tsd.c,v 1.23 2020/06/11 18:42:02 ad Exp $");
/* Functions and structures dealing with thread-specific data */
#include <errno.h>
@ -323,7 +323,6 @@ pthread__destroy_tsd(pthread_t self)
if (!self->pt_havespecific)
return;
pthread_mutex_unlock(&self->pt_lock);
/* Butenhof, section 5.4.2 (page 167):
*
@ -378,7 +377,6 @@ pthread__destroy_tsd(pthread_t self)
} while (!done && --iterations);
self->pt_havespecific = 0;
pthread_mutex_lock(&self->pt_lock);
}
void