Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
8a7d02b6
Commit
8a7d02b6
authored
Oct 30, 2011
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update GIL documentation
parent
6deb4fb4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
8 deletions
+17
-8
docs/src/userguide/external_C_code.rst
docs/src/userguide/external_C_code.rst
+13
-7
docs/src/userguide/parallelism.rst
docs/src/userguide/parallelism.rst
+4
-1
No files found.
docs/src/userguide/external_C_code.rst
View file @
8a7d02b6
...
@@ -416,16 +416,17 @@ available by all three methods.
...
@@ -416,16 +416,17 @@ available by all three methods.
Acquiring and Releasing the GIL
Acquiring and Releasing the GIL
---------------------------------
---------------------------------
Cython provides facilities for releasing the Global Interpreter Lock (GIL)
Cython provides facilities for acquiring and releasing the
before calling C code, and for acquiring the GIL in functions that are to be
`Global Interpreter Lock (GIL) <http://docs.python.org/dev/glossary.html#term-global-interpreter-lock>`_.
called back from C code that is executed without the GIL.
This may be useful when calling into (external C) code that may block, or when wanting to use Python from a
C callback.
.. _nogil:
.. _nogil:
Releasing the GIL
Releasing the GIL
^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^
You can release the GIL around a section of code using the
You can release the GIL around a section of code using the
:keyword:`with nogil` statement::
:keyword:`with nogil` statement::
with nogil:
with nogil:
...
@@ -446,10 +447,12 @@ header::
...
@@ -446,10 +447,12 @@ header::
cdef void my_callback(void *data) with gil:
cdef void my_callback(void *data) with gil:
...
...
If the callback may be called from another thread then the main thread which may not be a Python thread,
If the callback may be called from another non-Python thread,
care must be taken to initialize the GIL first, through a call to ``PyEval_InitThreads()``.
care must be taken to initialize the GIL first, through a call to
`PyEval_InitThreads() <http://docs.python.org/dev/c-api/init.html#PyEval_InitThreads>`_.
If you're already using :ref:`cython.parallel <parallel>` in your module, this will already have been taken care of.
The GIL may also be acquired through the ``with
nogil`` counterpart ``with gil``
::
The GIL may also be acquired through the ``with
gil`` statement
::
with gil:
with gil:
<execute this block with the GIL acquired>
<execute this block with the GIL acquired>
...
@@ -470,6 +473,9 @@ acquiring the GIL first. Some of these restrictions are currently checked by
...
@@ -470,6 +473,9 @@ acquiring the GIL first. Some of these restrictions are currently checked by
Cython, but not all. It is possible that more stringent checking will be
Cython, but not all. It is possible that more stringent checking will be
performed in the future.
performed in the future.
.. NOTE:: This declaration declares that it is safe to call the function without the GIL,
it does not in itself release the GIL.
Declaring a function with :keyword:`gil` also implicitly makes its signature
Declaring a function with :keyword:`gil` also implicitly makes its signature
:keyword:`nogil`.
:keyword:`nogil`.
docs/src/userguide/parallelism.rst
View file @
8a7d02b6
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
.. py:module:: cython.parallel
.. py:module:: cython.parallel
.. _parallel:
**********************************
**********************************
Using Parallelism
Using Parallelism
**********************************
**********************************
...
@@ -11,7 +13,8 @@ module. To use this kind of parallelism, the GIL must be released
...
@@ -11,7 +13,8 @@ module. To use this kind of parallelism, the GIL must be released
(see :ref:`Releasing the GIL <nogil>`).
(see :ref:`Releasing the GIL <nogil>`).
It currently supports OpenMP, but later on more backends might be supported.
It currently supports OpenMP, but later on more backends might be supported.
.. NOTE:: Because the backend is OpenMP, cython.parallel functionality may only be used from the main thread or from OpenMP threads.
.. NOTE:: Functionality in this module may only be used from the main thread
or parallel regions due to OpenMP restrictions.
__ nogil_
__ nogil_
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment