- http://www.gossamer-threads.com/lists/python/python/31447
- http://stackoverflow.com/questions/18892712/differnce-between-binary-add-and-inplace-add
- http://blog.ziade.org/2015/11/25/should-i-use-pythonoptimize/
- http://akaptur.com/blog/2013/08/14/python-bytecode-fun-with-dis/
- https://29a.ch/2009/2/20/atomic-get-and-increment-in-python
The GIL could not protect a += 1
and a = a + 1
both.
itertools.count()
is the only way for atomic increment in Python. It benefits from the C-implemented itertools
. Otherwise we need to around the inplace adding operation with threading.Lock()
.