Kaydet (Commit) 89c0ec9b authored tarafından Tim Peters's avatar Tim Peters

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.
üst 8470558a
...@@ -484,31 +484,24 @@ PyGILState_Release(PyGILState_STATE oldstate) ...@@ -484,31 +484,24 @@ PyGILState_Release(PyGILState_STATE oldstate)
assert(tcur->gilstate_counter >= 0); /* illegal counter value */ assert(tcur->gilstate_counter >= 0); /* illegal counter value */
/* If we are about to destroy this thread-state, we must /* If we are about to destroy this thread-state, we must
* clear it while the lock is held, as destructors may run. 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.
*/
if (tcur->gilstate_counter == 0) { if (tcur->gilstate_counter == 0) {
/* can't have been locked when we created it */ /* can't have been locked when we created it */
assert(oldstate == PyGILState_UNLOCKED); assert(oldstate == PyGILState_UNLOCKED);
PyThreadState_Clear(tcur); PyThreadState_Clear(tcur);
/* Delete this thread from our TLS */
PyThread_delete_key_value(autoTLSkey);
} }
/* Release the lock if necessary */ /* Release the lock if necessary */
if (oldstate == PyGILState_UNLOCKED) if (oldstate == PyGILState_UNLOCKED)
PyEval_ReleaseThread(tcur); PyEval_ReleaseThread(tcur);
/* Now complete destruction of the thread if necessary. This /* Now complete destruction of the thread if necessary */
* couldn't be done before PyEval_ReleaseThread() because if (tcur->gilstate_counter == 0) {
* PyThreadState_Delete doesn't allow deleting the current thread. /* Delete this thread from our TLS */
*/ PyThread_delete_key_value(autoTLSkey);
if (tcur->gilstate_counter == 0) /* Delete the thread-state */
PyThreadState_Delete(tcur); PyThreadState_Delete(tcur);
}
} }
#endif /* WITH_THREAD */ #endif /* WITH_THREAD */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment