diff options
author | Richard Oudkerk <shibturn@gmail.com> | 2013-11-17 17:03:19 (GMT) |
---|---|---|
committer | Richard Oudkerk <shibturn@gmail.com> | 2013-11-17 17:03:19 (GMT) |
commit | cfac5181ed4871baa0902f6d04000c6d56427749 (patch) | |
tree | 58eb98b6fab5a6131e4b7fe3cb5f441f3137ed22 /Doc/library/multiprocessing.rst | |
parent | 6b2b084192a4acf53249c47b44b1984d6c304a98 (diff) | |
parent | edcf8daaed24f1031b95a29aeef33f3b10c39571 (diff) | |
download | cpython-cfac5181ed4871baa0902f6d04000c6d56427749.zip cpython-cfac5181ed4871baa0902f6d04000c6d56427749.tar.gz cpython-cfac5181ed4871baa0902f6d04000c6d56427749.tar.bz2 |
Merge.
Diffstat (limited to 'Doc/library/multiprocessing.rst')
-rw-r--r-- | Doc/library/multiprocessing.rst | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index f3197eb..2c44dc9 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -1172,12 +1172,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. |