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: PyThreadState_Clear() docs incorrect
Type: Stage:
Components: Documentation Versions:
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: theller, tim.peters
Priority: normal Keywords:

Created on 2003-04-17 16:12 by theller, last changed 2022-04-10 16:08 by admin. This issue is now closed.

Messages (4)
msg15487 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2003-04-17 16:12
The docs state that the GIL must be held while
PyThreadStare_Clear() is called. This seems incorrect,
at least in Python 2.2 the thread state must not be
NULL under certain conditions.

See:
http://mail.python.org/pipermail/python-dev/2003-April/034574.html
msg15488 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2003-04-17 18:10
Logged In: YES 
user_id=31435

That was a confusing thread, and this is a confusing bug 
report <wink>.

Are you claiming that the GIL does not need to be held?  If 
not (and it doesn't seem that you were in the thread), it's 
unclear why you mention the GIL.

Best would be if you attached a patch incorporating what you 
think the resolution of that thread was.

msg15489 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2003-04-17 18:36
Logged In: YES 
user_id=11105

Sorry, that's because I'm still confused about thread
states, and I think the experts ;-) should sort this out.

No, I'm not claiming that the GIL does not need to be held,
I'm claiming that this is not sufficient: *in addition* the
current threadstate must not be NULL.

To quote from the mentioned posts:

I was doing this:

pts = PyThreadState_Swap(NULL);
PyThreadState_Clear(pts);
PyThreadState_Delete(pts);
PyEval_ReleaseLock();

and got a crash in PyThreadState_Clear(). If I understand
the current docs correctly, this should be allowed, so (my
conclusion) the docs are wrong.

I had to change the code in this way to avoid the crashes:

pts = PyThreadState_Get();
PyThreadState_Clear(pts);
pts = PyThreadState_Swap(NULL);
PyThreadState_Delete(pts);
PyEval_ReleaseLock();
msg15490 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2006-10-17 19:57
Logged In: YES 
user_id=11105

I retract this request.
History
Date User Action Args
2022-04-10 16:08:11adminsetgithub: 38319
2003-04-17 16:12:50thellercreate