Loading...
pthreads/pthread_tsd.c Libc-763.13 Libc-498
--- Libc/Libc-763.13/pthreads/pthread_tsd.c
+++ Libc/Libc-498/pthreads/pthread_tsd.c
@@ -187,10 +187,11 @@
 	int i, j;
 	void *param;
 
-	/* destroy dynamic keys first */
 	for (j = 0;  j < PTHREAD_DESTRUCTOR_ITERATIONS;  j++)
 	{
-		for (i = __pthread_tsd_start;  i <= self->max_tsd_key;  i++)
+		/* The first slot is reserved for pthread_self() */
+
+		for (i = __pthread_tsd_first;  i <= __pthread_tsd_max;  i++)
 		{
 			if (_pthread_keys[i].created && (param = self->tsd[i]))
 			{
@@ -201,16 +202,7 @@
 				}
 			}
 		}
-	}
-
-	self->max_tsd_key = 0;
-
-	/* 
-	 * The first slot is reserved for pthread_self() and there is no cleanup on it.
-	 * Destroy rest of the static keys next only if any destructors registered.
-	 */
-	for (j = 0;  j < PTHREAD_DESTRUCTOR_ITERATIONS;  j++) {
-		for (i = __pthread_tsd_first;  i <= __pthread_tsd_max;  i++)
+		for (i = __pthread_tsd_start;  i <= self->max_tsd_key;  i++)
 		{
 			if (_pthread_keys[i].created && (param = self->tsd[i]))
 			{
@@ -222,6 +214,7 @@
 			}
 		}
 	}
+	self->max_tsd_key = 0;
 }
 
 int