This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Bug #1011380 alternate fix - locking is noop without threads
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: tim.peters Nosy List: gustavo, ncoghlan, tim.peters
Priority: normal Keywords: patch

Created on 2004-10-10 16:59 by ncoghlan, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
threads_initialized.diff ncoghlan, 2004-10-10 16:59 Alternate fix for bug #1011380
threads_initialized_api.diff ncoghlan, 2004-10-10 18:27 Add the PyEval_ThreadsInitialized() API
threads_initialized_api_doc.diff ncoghlan, 2004-10-10 18:50 Documentation for PyEval_ThreadsInitialized
Messages (6)
msg47048 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2004-10-10 16:59
Bug# 1011380 points out that locking operations such as
PyGILState_Ensure and PyGILState_Release should be
noop's if PyEval_InitThreads has not been called.

However, for reasons stated there, I dislike the
mechanism used in the patch supplied with the bug
report. The patch attached here uses a different mechanism:

 - within ceval.c, the PyEval_(Thread/Lock) functions
all use the existence of the GIL to check if
PyEval_InitThreads has been called. This matches
existing usage in ceval.c
 - a new API function PyEval_ThreadsInitialized() is
added to ceval.h that returns a true result only if the
GIL exists.
 - this new API is used by the PyGILState functions to
short-circuit their operation if the GIL does not exist.
msg47049 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-10-10 17:26
Logged In: YES 
user_id=31435

As with the other patch, it's not acceptable to slow down 
every locking function in the core.  It would be fine to add 
PyEval_ThreadsInitialized() to the API.  Doing any more than 
just that is debatable, requires doc changes, etc.

Note that most of this patch appears to consist of 
whitespace changes.  Those should be checked in separately.
msg47050 - (view) Author: Gustavo J. A. M. Carneiro (gustavo) * Date: 2004-10-10 18:11
Logged In: YES 
user_id=908

Yes, PyEval_ThreadsInitialized() API is sufficient for what
I want.  Making GIL functions noops would be icing on the
cake, but I can live without it.  Thanks ncoghlan!
msg47051 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2004-10-10 18:27
Logged In: YES 
user_id=1038590

API only version of the patch attached. (I should really
remember to use -w when generating C-code diffs)
msg47052 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2004-10-10 18:50
Logged In: YES 
user_id=1038590

Doc patch for PyEval_ThreadsInitialized attached.
msg47053 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-10-11 02:41
Logged In: YES 
user_id=31435

Thanks!  Applied with minor changes, and also purged 
_PyThread_Started.
History
Date User Action Args
2022-04-11 14:56:07adminsetgithub: 41000
2004-10-10 16:59:09ncoghlancreate