Richard Oudkerk added the comment:
> I thought that access to the value field of Value instances was
> protected by locks to avoid lost updates.
Loads and stores are both atomic. But "+=" is made up of two operations, a
load followed by a store, and the lock is dropped between the two.
The same lack of atomicity applies when using "+=" to modify an attribute of a
normal python object in a multithreaded program.
If you want an atomic increment you could try
def do_inc(integer):
with integer.get_lock():
integer.value += 1
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue16998>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com