Thread safetyness in Python

Oren Tirosh oren-py-l at hishome.net
Wed Jul 3 11:26:34 EDT 2002


On Wed, Jul 03, 2002 at 09:34:14AM -0500, Jeff Epler wrote:
> On Wed, Jul 03, 2002 at 09:58:51AM -0400, Oren Tirosh wrote:
> > The resolution is one bytecode operation so a+=1 is atomic but not a=a+1.
> > The list operations above are atomic.
> 
> a+=1 is multiple bytecodes.

          6 LOAD_FAST                0 (a)
          9 LOAD_CONST               1 (1)
         12 INPLACE_ADD
         13 STORE_FAST               0 (a)

You're right.  I forgot that the inplace operations also need to store the 
new object afterwards since immutable objects such as ints cannot really be 
modified "in place".

So a+=1 isn't atomic, but l+=[1] is. Interesting.

	Oren






More information about the Python-list mailing list