Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyGILState_Ensure()/PyGILState_Release() documentation incomplete? #49549

Closed
osvenskan mannequin opened this issue Feb 17, 2009 · 2 comments
Closed

PyGILState_Ensure()/PyGILState_Release() documentation incomplete? #49549

osvenskan mannequin opened this issue Feb 17, 2009 · 2 comments
Assignees
Labels
docs Documentation in the Doc dir

Comments

@osvenskan
Copy link
Mannequin

osvenskan mannequin commented Feb 17, 2009

BPO 5299
Nosy @birkenfeld, @osvenskan

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/birkenfeld'
closed_at = <Date 2009-04-05.17:19:22.475>
created_at = <Date 2009-02-17.20:43:24.445>
labels = ['docs']
title = 'PyGILState_Ensure()/PyGILState_Release() documentation incomplete?'
updated_at = <Date 2009-04-05.17:19:22.474>
user = 'https://github.com/osvenskan'

bugs.python.org fields:

activity = <Date 2009-04-05.17:19:22.474>
actor = 'georg.brandl'
assignee = 'georg.brandl'
closed = True
closed_date = <Date 2009-04-05.17:19:22.475>
closer = 'georg.brandl'
components = ['Documentation']
creation = <Date 2009-02-17.20:43:24.445>
creator = 'osvenskan'
dependencies = []
files = []
hgrepos = []
issue_num = 5299
keywords = []
message_count = 2.0
messages = ['82366', '85529']
nosy_count = 2.0
nosy_names = ['georg.brandl', 'osvenskan']
pr_nums = []
priority = 'normal'
resolution = 'works for me'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue5299'
versions = ['Python 2.6', 'Python 2.5', 'Python 2.4', 'Python 3.0', 'Python 3.1', 'Python 2.7']

@osvenskan
Copy link
Mannequin Author

osvenskan mannequin commented Feb 17, 2009

The threading API documentation might omit out some important
information about the GIL.

The GIL can be acquired by explicitly calling PyEval_AcquireLock(). One
can also acquire the GIL by calling PyGILState_Ensure(). The latter
differs from the former in that calling PyGILState_Ensure() when one
already has the GIL will not create deadlock. This is implied; it would
be helpful if this was explicitly stated.

Likewise, I assume that the Nth call to PyGILState_Release() releases
the GIL, where N = the number of calls made previously to
PyGILState_Ensure(). But I don't know this and the documentation doesn't
make it clear.

As a first-time user of the API, it makes me nervous to call
PyGILState_Ensure() which acquires the GIL without knowing for sure that
PyGILState_Release() releases it. I can't evaluate my code for logical
correctness, and when dealing with threads and the GIL, neither can I be
sure that timing-dependent bugs will show up in testing. As a result, my
code feels fragile.

I don't understand how the code works well enough to suggest better
documentation. If nothing else, it would be useful to see something that
promises that as long as each call to PyGILState_Ensure() is matched
with a call to PyGILState_Release(), the GIL will take care of itself.

@osvenskan osvenskan mannequin assigned birkenfeld Feb 17, 2009
@osvenskan osvenskan mannequin added the docs Documentation in the Doc dir label Feb 17, 2009
@birkenfeld
Copy link
Member

I think the paragraph

Every call to :cfunc:`PyGILState_Ensure` must be matched by a call to
:cfunc:`PyGILState_Release` on the same thread.

says exactly what you want to know.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

1 participant