From b36e5d627d4232a01850707eb78a5067f3fd77f4 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 29 Apr 2019 11:15:56 +0200 Subject: bpo-36356: Destroy the GIL at exit (GH-12453) * Add _PyEval_FiniThreads2(). _PyEval_FiniThreads() now only clears the pending lock, whereas _PyEval_FiniThreads2() destroys the GIL. * pymain_free() now calls _PyEval_FiniThreads2(). * Py_FinalizeEx() now calls _PyEval_FiniThreads(). --- Python/ceval.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'Python/ceval.c') diff --git a/Python/ceval.c b/Python/ceval.c index ccd0427a14..5480fbacaf 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -188,8 +188,19 @@ PyEval_InitThreads(void) } } + void _PyEval_FiniThreads(void) +{ + if (_PyRuntime.ceval.pending.lock != NULL) { + PyThread_free_lock(_PyRuntime.ceval.pending.lock); + _PyRuntime.ceval.pending.lock = NULL; + } +} + + +void +_PyEval_FiniThreads2(void) { if (!gil_created()) { return; @@ -197,11 +208,6 @@ _PyEval_FiniThreads(void) destroy_gil(); assert(!gil_created()); - - if (_PyRuntime.ceval.pending.lock != NULL) { - PyThread_free_lock(_PyRuntime.ceval.pending.lock); - _PyRuntime.ceval.pending.lock = NULL; - } } static inline void -- cgit v1.2.1