Frank Millman <fr***@chagford.comwrites:
Just out of interest, would the following, without a lock, be safe?
old, atomic_int = atomic_int, atomic_int+1
No I don't think so. But I'm told that in CPython, you can say
counter = iter(xrange(10000000)) # some number that exceeds what you'll use
...
atomic_int = counter.next()
and the GIL keeps it safe. When in doubt, use a lock or communicate
with other threads through Queues.