[Python-bugs-list] [ python-Bugs-723205 ] PyThreadState_Clear() docs incorrect

SourceForge.net noreply@sourceforge.net
Thu, 17 Apr 2003 11:36:53 -0700


Bugs item #723205, was opened at 2003-04-17 18:12
Message generated for change (Comment added) made by theller
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=723205&group_id=5470

Category: Documentation
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Thomas Heller (theller)
Assigned to: Nobody/Anonymous (nobody)
Summary: PyThreadState_Clear() docs incorrect

Initial Comment:
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


----------------------------------------------------------------------

>Comment By: Thomas Heller (theller)
Date: 2003-04-17 20:36

Message:
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();

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2003-04-17 20:10

Message:
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.



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=723205&group_id=5470