GIL in Python 3.1

后端 未结 7 753
悲&欢浪女
悲&欢浪女 2020-12-31 05:13

Does anybody knows fate of Global Interpreter Lock in Python 3.1 against C++ multithreading integration

7条回答
  •  忘掉有多难
    2020-12-31 05:38

    I guess there will always be a GIL. The reason is performance. Making all the low level access thread safe - means putting a mutex around each hash operation etc. is heavy. Remember that a simple statement like

    self.foo(self.bar, 3, val)
    

    Might already have at least 3 (if val is a global) hashtable lookups at the moment and maybe even much more if the method cache is not hot (depending on the inheritance depth of the class)

    It's expensive - that's why Java dropped the idea and introduced hashtables which do not use a monitor call to get rid of its "Java Is Slow" trademark.

提交回复
热议问题