Threads

Emile van Sebille emile at fenx.com
Sat May 18 09:06:20 EDT 2002


"Robert Cunningham" <r.j.cunningham at virgin.net> wrote in message
news:zgsF8.571$xY.84445 at newsfep1-win.server.ntli.net...
> Hopefully someone can clarify this for me, I have n threads running
and a global
> var c now sometimes these threads may update c (c += 1 or c -= 1). My
question
> is do I need to use a lock or something, at the moment I don't, I
assumed += is
> 'atomic' - am I right??
>

Doesn't look like it:

>>> import dis
>>> def test(): c+=1
...
>>> dis.dis(test)
          0 SET_LINENO               1

          3 SET_LINENO               1
          6 LOAD_FAST                0 (c)
          9 LOAD_CONST               1 (1)
         12 INPLACE_ADD
         13 STORE_FAST               0 (c)
         16 LOAD_CONST               0 (None)
         19 RETURN_VALUE

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list