diff options
author | Brent Stapleton <brent.stapleton@ettus.com> | 2018-11-21 14:25:21 -0800 |
---|---|---|
committer | Brent Stapleton <bstapleton@g.hmc.edu> | 2018-11-29 17:49:30 -0800 |
commit | 51464174d47d767a6aa008bd8bf31cfb7290ff7b (patch) | |
tree | c52806173a225843af1092a2408b62d0aab5e099 | |
parent | 3c134a29415e4f218e79e63d8890603e69cfe914 (diff) | |
download | uhd-51464174d47d767a6aa008bd8bf31cfb7290ff7b.tar.gz uhd-51464174d47d767a6aa008bd8bf31cfb7290ff7b.tar.bz2 uhd-51464174d47d767a6aa008bd8bf31cfb7290ff7b.zip |
docs: python: add documentation on GIL release
Adding documentation explaining where the Python API releases the
Python GIL, and what that means for users.
-rw-r--r-- | host/docs/pythonapi.dox | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/host/docs/pythonapi.dox b/host/docs/pythonapi.dox index 2617c6141..e290f1ea5 100644 --- a/host/docs/pythonapi.dox +++ b/host/docs/pythonapi.dox @@ -93,5 +93,28 @@ def recv_to_file(): This kind of API is particularly useful in combination with Jupyter Notebooks or similar interactive environments. +\section python_usage_gil Python Global Interpreter Lock + +From the <a href="https://wiki.python.org/moin/GlobalInterpreterLock">Python wiki page on the GIL:</a> +> In CPython, the global interpreter lock, or GIL, is a mutex that protects +> access to Python objects, preventing multiple threads from executing Python +> bytecodes at once. + +During some performance-critical function calls, the UHD Python API releases the +GIL, during which Python objects have their contents modified. The functions +calls which do so are uhd::rx_streamer::recv, uhd::tx_streamer::send, and +uhd::tx_streamer::recv_async_msg. To be clear, the functions listed here violate +the expected contract set out by the GIL by accessing Python objects (from C++) +without holding the GIL. This is necessary to achieve rates similar to what the +C++ API can provide. + +To this end, users must ensure that the Python objects accessed by the listed +functions are handled with care. In simple, single threaded applications, this +won't require any extra work. However, in more complicated and/or multi- +threaded applications, steps must be taken to avoid thread-unsafe behavior. For +example, if an application needs to call recv() in one thread, and access the +sample buffer from another thread, a synchronization method (ie. a mutex) must +be used to safeguard access to that buffer. + */ // vim:ft=doxygen: |