Mercurial > cpython-lru_cache-weakref
comparison Python/pystate.c @ 33714:635dd8a9ebd9 legacy-trunk
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.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Sun, 10 Oct 2004 05:30:40 +0000 |
| parents | 517e4ec0df89 |
| children | dfd07b7be407 |
comparison
equal
deleted
inserted
replaced
| 33713:517e4ec0df89 | 33714:635dd8a9ebd9 |
|---|---|
| 482 assert(PyThreadState_IsCurrent(tcur)); | 482 assert(PyThreadState_IsCurrent(tcur)); |
| 483 --tcur->gilstate_counter; | 483 --tcur->gilstate_counter; |
| 484 assert(tcur->gilstate_counter >= 0); /* illegal counter value */ | 484 assert(tcur->gilstate_counter >= 0); /* illegal counter value */ |
| 485 | 485 |
| 486 /* If we are about to destroy this thread-state, we must | 486 /* If we are about to destroy this thread-state, we must |
| 487 * clear it while the lock is held, as destructors may run. | 487 clear it while the lock is held, as destructors may run |
| 488 * In addition, we have to delete out TLS entry, which is keyed | 488 */ |
| 489 * by thread id, while the GIL is held: the thread calling us may | |
| 490 * go away, and a new thread may be created with the same thread | |
| 491 * id. If we don't delete our TLS until after the GIL is released, | |
| 492 * that new thread may manage to insert a TLS value with the same | |
| 493 * thread id as ours, and then we'd erroneously delete it. | |
| 494 */ | |
| 495 if (tcur->gilstate_counter == 0) { | 489 if (tcur->gilstate_counter == 0) { |
| 496 /* can't have been locked when we created it */ | 490 /* can't have been locked when we created it */ |
| 497 assert(oldstate == PyGILState_UNLOCKED); | 491 assert(oldstate == PyGILState_UNLOCKED); |
| 498 PyThreadState_Clear(tcur); | 492 PyThreadState_Clear(tcur); |
| 499 /* Delete this thread from our TLS */ | |
| 500 PyThread_delete_key_value(autoTLSkey); | |
| 501 } | 493 } |
| 502 | 494 |
| 503 /* Release the lock if necessary */ | 495 /* Release the lock if necessary */ |
| 504 if (oldstate == PyGILState_UNLOCKED) | 496 if (oldstate == PyGILState_UNLOCKED) |
| 505 PyEval_ReleaseThread(tcur); | 497 PyEval_ReleaseThread(tcur); |
| 506 | 498 |
| 507 /* Now complete destruction of the thread if necessary. This | 499 /* Now complete destruction of the thread if necessary */ |
| 508 * couldn't be done before PyEval_ReleaseThread() because | 500 if (tcur->gilstate_counter == 0) { |
| 509 * PyThreadState_Delete doesn't allow deleting the current thread. | 501 /* Delete this thread from our TLS */ |
| 510 */ | 502 PyThread_delete_key_value(autoTLSkey); |
| 511 if (tcur->gilstate_counter == 0) | 503 /* Delete the thread-state */ |
| 512 PyThreadState_Delete(tcur); | 504 PyThreadState_Delete(tcur); |
| 505 } | |
| 513 } | 506 } |
| 514 #endif /* WITH_THREAD */ | 507 #endif /* WITH_THREAD */ |
