Author sbt
Recipients lechten, sbt
Date 2013-01-19.22:18:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1358633888.74.0.0672288305869.issue16998@psf.upfronthosting.co.za>
In-reply-to
Content
> 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
History
Date User Action Args
2013-01-19 22:18:08sbtsetrecipients: + sbt, lechten
2013-01-19 22:18:08sbtsetmessageid: <1358633888.74.0.0672288305869.issue16998@psf.upfronthosting.co.za>
2013-01-19 22:18:08sbtlinkissue16998 messages
2013-01-19 22:18:07sbtcreate