summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorRichard Oudkerk <shibturn@gmail.com>2013-11-17 17:00:38 (GMT)
committerRichard Oudkerk <shibturn@gmail.com>2013-11-17 17:00:38 (GMT)
commitedcf8daaed24f1031b95a29aeef33f3b10c39571 (patch)
treeddb87c1030eb7513f666bffcdd3e4cf323760c73 /Doc/library
parent9eefe91fc2922de7ae7eee2e55d17ea452468083 (diff)
downloadcpython-edcf8daaed24f1031b95a29aeef33f3b10c39571.zip
cpython-edcf8daaed24f1031b95a29aeef33f3b10c39571.tar.gz
cpython-edcf8daaed24f1031b95a29aeef33f3b10c39571.tar.bz2
Issue 16998: Clarify that += on a shared value is not atomic.
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/multiprocessing.rst24
1 files changed, 18 insertions, 6 deletions
diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst
index b2ed544..3d1c209 100644
--- a/Doc/library/multiprocessing.rst
+++ b/Doc/library/multiprocessing.rst
@@ -1006,12 +1006,24 @@ inherited by child processes.
ctypes type or a one character typecode of the kind used by the :mod:`array`
module. *\*args* is passed on to the constructor for the type.
- If *lock* is ``True`` (the default) then a new lock object is created to
- synchronize access to the value. If *lock* is a :class:`Lock` or
- :class:`RLock` object then that will be used to synchronize access to the
- value. If *lock* is ``False`` then access to the returned object will not be
- automatically protected by a lock, so it will not necessarily be
- "process-safe".
+ If *lock* is ``True`` (the default) then a new recursive lock
+ object is created to synchronize access to the value. If *lock* is
+ a :class:`Lock` or :class:`RLock` object then that will be used to
+ synchronize access to the value. If *lock* is ``False`` then
+ access to the returned object will not be automatically protected
+ by a lock, so it will not necessarily be "process-safe".
+
+ Operations like ``+=`` which involve a read and write are not
+ atomic. So if, for instance, you want to atomically increment a
+ shared value it is insufficient to just do ::
+
+ counter.value += 1
+
+ Assuming the associated lock is recursive (which it is by default)
+ you can instead do ::
+
+ with counter.get_lock():
+ counter.value += 1
Note that *lock* is a keyword-only argument.