summaryrefslogtreecommitdiffstats
path: root/Python/ceval_gil.c
Commit message (Collapse)AuthorAgeFilesLines
* [3.12] gh-108987: Fix _thread.start_new_thread() race condition (#109135) ↵Victor Stinner2023-10-041-25/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | (#110342) * gh-108987: Fix _thread.start_new_thread() race condition (#109135) Fix _thread.start_new_thread() race condition. If a thread is created during Python finalization, the newly spawned thread now exits immediately instead of trying to access freed memory and lead to a crash. thread_run() calls PyEval_AcquireThread() which checks if the thread must exit. The problem was that tstate was dereferenced earlier in _PyThreadState_Bind() which leads to a crash most of the time. Move _PyThreadState_CheckConsistency() from thread_run() to _PyThreadState_Bind(). (cherry picked from commit 517cd82ea7d01b344804413ef05610934a43a241) * gh-109795: `_thread.start_new_thread`: allocate thread bootstate using raw memory allocator (#109808) (cherry picked from commit 1b8f2366b38c87b0450d9c15bdfdd4c4a2fc3a01) --------- Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com>
* [3.12] gh-104690: thread_run() checks for tstate dangling pointer (#109056) ↵Victor Stinner2023-10-021-18/+8
| | | | | | | | | | | | | | (#109133) gh-104690: thread_run() checks for tstate dangling pointer (#109056) thread_run() of _threadmodule.c now calls _PyThreadState_CheckConsistency() to check if tstate is a dangling pointer when Python is built in debug mode. Rename ceval_gil.c is_tstate_valid() to _PyThreadState_CheckConsistency() to reuse it in _threadmodule.c. (cherry picked from commit f63d37877ad166041489a968233b57540f8456e8)
* [3.12] gh-104812: Run Pending Calls in any Thread (gh-104813) (gh-105752)Eric Snow2023-06-141-82/+131
| | | | For a while now, pending calls only run in the main thread (in the main interpreter). This PR changes things to allow any thread run a pending call, unless the pending call was explicitly added for the main thread to run. (cherry picked from commit 757b402)
* [3.12] gh-104341: Call _PyEval_ReleaseLock() with NULL When Finalizing the ↵Miss Islington (bot)2023-06-011-4/+26
| | | | | | | | | | Current Thread (gh-105109) (gh-105209) This avoids the problematic race in drop_gil() by skipping the FORCE_SWITCHING code there for finalizing threads. (The idea for this approach came out of discussions with @markshannon.) (cherry picked from commit 3698fda) Co-authored-by: Eric Snow ericsnowcurrently@gmail.com
* gh-104341: Adjust tstate_must_exit() to Respect Interpreter Finalization ↵Eric Snow2023-05-151-0/+3
| | | | | (gh-104437) With the move to a per-interpreter GIL, this check slipped through the cracks.
* gh-99113: A Per-Interpreter GIL! (gh-104210)Eric Snow2023-05-081-42/+13
| | | | | This is the culmination of PEP 684 (and of my 8-year long multi-core Python project)! Each subinterpreter may now be created with its own GIL (via Py_NewInterpreterFromConfig()). If not so configured then the interpreter will share with the main interpreter--the status quo since subinterpreters were added decades ago. The main interpreter always has its own GIL and subinterpreters from Py_NewInterpreter() will always share with the main interpreter.
* gh-99113: Make Sure the GIL is Acquired at the Right Places (gh-104208)Eric Snow2023-05-061-27/+57
| | | This is a pre-requisite for a per-interpreter GIL. Without it this change isn't strictly necessary. However, there is no real downside otherwise.
* gh-104233: Fix "unused variable" warning in `ceval_gil.c` (#104234)Nikita Sobolev2023-05-061-0/+2
|
* gh-99113: Add PyInterpreterConfig.own_gil (gh-104204)Eric Snow2023-05-051-1/+22
| | | | | We also add PyInterpreterState.ceval.own_gil to record if the interpreter actually has its own GIL. Note that for now we don't actually respect own_gil; all interpreters still share the one GIL. However, PyInterpreterState.ceval.own_gil does reflect PyInterpreterConfig.own_gil. That lie is a temporary one that we will fix when the GIL really becomes per-interpreter.
* gh-99113: Share the GIL via PyInterpreterState.ceval.gil (gh-104203)Eric Snow2023-05-051-38/+59
| | | In preparation for a per-interpreter GIL, we add PyInterpreterState.ceval.gil, set it to the shared GIL for each interpreter, and use that rather than using _PyRuntime.ceval.gil directly. Note that _PyRuntime.ceval.gil is still the actual GIL.
* gh-103323: Remove PyRuntimeState_GetThreadState() (#104171)Victor Stinner2023-05-041-3/+2
| | | | | This function no longer makes sense, since its runtime parameter is no longer used. Use directly _PyThreadState_GET() and _PyInterpreterState_GET() instead.
* gh-103167: Fix `-Wstrict-prototypes` warnings by using `(void)` for ↵Nikita Sobolev2023-04-051-1/+1
| | | | functions with no args (GH-103168)
* gh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives ↵Irit Katriel2023-02-281-4/+3
| | | | (in Python/) (#102193)
* gh-59956: Clarify Runtime State Status Expectations (gh-101308)Eric Snow2023-01-301-1/+1
| | | | | | | | | | | | | A PyThreadState can be in one of many states in its lifecycle, represented by some status value. Those statuses haven't been particularly clear, so we're addressing that here. Specifically: * made the distinct lifecycle statuses clear on PyThreadState * identified expectations of how various lifecycle-related functions relate to status * noted the various places where those expectations don't match the actual behavior At some point we'll need to address the mismatches. (This change also includes some cleanup.) https://github.com/python/cpython/issues/59956
* gh-59956: Clarify GILState-related Code (gh-101161)Eric Snow2023-01-191-8/+6
| | | | | | | | | | The objective of this change is to help make the GILState-related code easier to understand. This mostly involves moving code around and some semantically equivalent refactors. However, there are a also a small number of slight changes in structure and behavior: * tstate_current is moved out of _PyRuntimeState.gilstate * autoTSSkey is moved out of _PyRuntimeState.gilstate * autoTSSkey is initialized earlier * autoTSSkey is re-initialized (after fork) earlier https://github.com/python/cpython/issues/59956
* gh-81057: Move More Globals in Core Code to _PyRuntimeState (gh-99516)Eric Snow2022-11-161-5/+4
| | | https://github.com/python/cpython/issues/81057
* gh-97922: Run the GC only on eval breaker (#97920)Pablo Galindo Salgado2022-10-081-10/+20
|
* gh-96387: take_gil() resets drop request before exit (#96869)Victor Stinner2022-09-191-0/+11
| | | | | | | | | | | | | At Python exit, sometimes a thread holding the GIL can wait forever for a thread (usually a daemon thread) which requested to drop the GIL, whereas the thread already exited. To fix the race condition, the thread which requested the GIL drop now resets its request before exiting. take_gil() now calls RESET_GIL_DROP_REQUEST() before PyThread_exit_thread() if it called SET_GIL_DROP_REQUEST to fix a race condition with drop_gil(). Issue discovered and analyzed by Mingliang ZHAO.
* GH-96177: Move GIL and eval breaker code out of ceval.c into ceval_gil.c. ↵Mark Shannon2022-08-241-0/+986
(GH-96204)