Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 371d98a

Browse files
committed
[Bug #987835] Add documentation from PEP 311. (Untested TeX code.)
1 parent 3f41974 commit 371d98a

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Doc/api/init.tex

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,42 @@ \section{Thread State and the Global Interpreter Lock
699699
\versionadded{2.3}
700700
\end{cfuncdesc}
701701

702+
\begin{cfuncdesc}{PyGILState_STATE}{PyGILState_Ensure}{}
703+
Ensure that the current thread is ready to call the Python
704+
C API regardless of the current state of Python, or of its
705+
thread lock. This may be called as many times as desired
706+
by a thread as long as each call is matched with a call to
707+
\cfunction{PyGILState_Release()}.
708+
In general, other thread-related APIs may
709+
be used between \cfunction{PyGILState_Ensure()} and \cfunction{PyGILState_Release()} calls as long as the
710+
thread state is restored to its previous state before the Release().
711+
For example, normal usage of the \csimplemacro{Py_BEGIN_ALLOW_THREADS}
712+
and \csimplemacro{Py_END_ALLOW_THREADS} macros is acceptable.
713+
714+
The return value is an opaque "handle" to the thread state when
715+
\cfunction{PyGILState_Acquire()} was called, and must be passed to
716+
\cfunction{PyGILState_Release()} to ensure Python is left in the same
717+
state. Even though recursive calls are allowed, these handles
718+
\emph{cannot} be shared - each unique call to
719+
\cfunction{PyGILState_Ensure} must save the handle for its call to
720+
\cfunction{PyGILState_Release}.
721+
722+
When the function returns, the current thread will hold the GIL.
723+
Failure is a fatal error.
724+
\versionadded{2.3}
725+
\end{cfuncdesc}
726+
727+
\begin{cfuncdesc}{void}{PyGILState_Release}{PyGILState_STATE}
728+
Release any resources previously acquired. After this call, Python's
729+
state will be the same as it was prior to the corresponding
730+
\cfunction{PyGILState_Ensure} call (but generally this state will be unknown to
731+
the caller, hence the use of the GILState API.)
732+
733+
Every call to \cfunction{PyGILState_Ensure()} must be matched by a call to
734+
\cfunction{PyGILState_Release()} on the same thread.
735+
\versionadded{2.3}
736+
\end{cfuncdesc}
737+
702738

703739
\section{Profiling and Tracing \label{profiling}}
704740

0 commit comments

Comments
 (0)