> > > That's quite an interesting idea. I do think a lot of production Python > code implicitly depends on the GIL and would need rework for multicore. > For example, code that expects "n += 1" to be atomic, because the > CPython bytecode interpreter won't switch threads in the middle of it. > -- >
Yes it will. The interpreter may switch threads between any of these bytecode instructions. In [8]: dis.dis(compile('n += 1', '', 'single')) 1 0 LOAD_NAME 0 (n) 3 LOAD_CONST 0 (1) 6 INPLACE_ADD 7 STORE_NAME 0 (n) 10 LOAD_CONST 1 (None) 13 RETURN_VALUE Proof: In [15]: n = 0 In [16]: class Foo(threading.Thread): ....: def run(self): ....: global n ....: for i in range(10000): ....: n += 1 ....: ....: In [17]: threads = [Foo() for i in range(5)] In [18]: for thread in threads: ....: thread.start() ....: ....: In [19]: n Out[19]: 37433
-- http://mail.python.org/mailman/listinfo/python-list