[Python-checkins] python/dist/src/Python pystate.c,2.36,2.37

tim_one at users.sourceforge.net tim_one at users.sourceforge.net
Sun Oct 10 07:30:43 CEST 2004


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24384/Python

Modified Files:
	pystate.c 
Log Message:
Revert rev 2.35.  It was based on erroneous reasoning -- the current
thread's id can't get duplicated, because (of course!) the current thread
is still running.  The code should work either way, but reverting the
gratuitous change should make backporting easier, and gets the bad
reasoning out of 2.35's new comments.


Index: pystate.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pystate.c,v
retrieving revision 2.36
retrieving revision 2.37
diff -u -d -r2.36 -r2.37
--- pystate.c	10 Oct 2004 02:47:33 -0000	2.36
+++ pystate.c	10 Oct 2004 05:30:40 -0000	2.37
@@ -484,31 +484,24 @@
 	assert(tcur->gilstate_counter >= 0); /* illegal counter value */
 
 	/* If we are about to destroy this thread-state, we must
-	 * clear it while the lock is held, as destructors may run.
-	 * In addition, we have to delete out TLS entry, which is keyed
-	 * by thread id, while the GIL is held:  the thread calling us may
-	 * go away, and a new thread may be created with the same thread
-	 * id.  If we don't delete our TLS until after the GIL is released,
-	 * that new thread may manage to insert a TLS value with the same
-	 * thread id as ours, and then we'd erroneously delete it.
-	 */
+	   clear it while the lock is held, as destructors may run
+	*/
 	if (tcur->gilstate_counter == 0) {
 		/* can't have been locked when we created it */
 		assert(oldstate == PyGILState_UNLOCKED);
 		PyThreadState_Clear(tcur);
-		/* Delete this thread from our TLS */
-		PyThread_delete_key_value(autoTLSkey);
 	}
 
 	/* Release the lock if necessary */
 	if (oldstate == PyGILState_UNLOCKED)
 		PyEval_ReleaseThread(tcur);
 
-	/* Now complete destruction of the thread if necessary.  This
-	 * couldn't be done before PyEval_ReleaseThread() because
-	 * PyThreadState_Delete doesn't allow deleting the current thread.
-	 */
-	if (tcur->gilstate_counter == 0)
+	/* Now complete destruction of the thread if necessary */
+	if (tcur->gilstate_counter == 0) {
+		/* Delete this thread from our TLS */
+		PyThread_delete_key_value(autoTLSkey);
+		/* Delete the thread-state */
 		PyThreadState_Delete(tcur);
+	}
 }
 #endif /* WITH_THREAD */



More information about the Python-checkins mailing list