[Cython] Why is 'with gil' disabled in the parser? Any good reason?
Sturla Molden
sturla at molden.no
Fri Mar 6 15:04:28 CET 2009
On 3/6/2009 2:48 PM, Sturla Molden wrote:
> {
> PyGILState_STATE _gilstate = PyGILState_Ensure();
>
> /* now we have the GIL */
>
> PyGILState_Release(_gilstate);
> }
What this means is PyGILState_Release does not release the GIL. It just
resets the GIL to whatever it was before PyGILState_Ensure was called. So,
{
/* We might or might not hold the GIL. */
PyGILState_STATE _gilstate = PyGILState_Ensure();
/* We have the GIL.
Now its safe to use the rest of Python's C API. */
PyGILState_Release(_gilstate);
/* We might or might not hold the GIL. */
}
Thus,
with nogil:
with gil:
with gil:
with nogil:
<suite>
Would be
Py_BEGIN_ALLOW_THREADS
{
PyGILState_STATE _gilstate = PyGILState_Ensure();
{
PyGILState_STATE _gilstate = PyGILState_Ensure();
{
Py_BEGIN_ALLOW_THREADS
{
/*suite*/
}
Py_END_ALLOW_THREADS
}
PyGILState_Release(_gilstate);
}
PyGILState_Release(_gilstate);
}
Py_END_ALLOW_THREADS
S.M.
More information about the Cython-dev
mailing list