AlFire wrote:
Hi,
all is very simple and by the end of the program life I expect the counter to zero out.

however I am getting values -1, -2, 1 ,2 ,3 and quite often 0 as expected.

I guarded those statement with Lock.{acquire,release} and now it always returns 0.


But I still can not believe that +=1 is not a thread safe operation.


Any clue?

   "counter += 1" is not an atomic operation, apparently.  Sorry.

   However, appending and removing from a list or dict are atomic operations,
because if they were not, memory allocation would break.

                                                John Nagle
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to