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

Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix Sphinx code block.
  • Loading branch information
ZeroIntensity committed Jan 6, 2025
commit 32a885feee29c3a4b4397a50016d3c186478e119
22 changes: 12 additions & 10 deletions Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -887,16 +887,18 @@ In ctypes, reads and writes to a single object concurrently is safe, but not acr
In the above, it's only safe for one object to read and write to the address at once if the :term:`GIL` is disabled.
Comment thread
ZeroIntensity marked this conversation as resolved.
Outdated
So, ``pointer_a`` can be shared and written to across multiple threads, but only if ``pointer_b``
is not also attempting to do the same. If this is an issue, consider using a :class:`threading.Lock`
to synchronize access to memory.::

>>> import threading
>>> lock = threading.Lock()
>>> # Thread 1
>>> with lock:
... pointer_a.contents = 24
>>> # Thread 2
>>> with lock:
... pointer_b.contents = 42
to synchronize access to memory:

.. code-block:: pycon

>>> import threading
>>> lock = threading.Lock()
>>> # Thread 1
>>> with lock:
... pointer_a.contents = 24
>>> # Thread 2
>>> with lock:
... pointer_b.contents = 42

.. seealso::

Expand Down