操作系统OS,Python - 有了GIL为什么还要threading.Lock()?

python

参考:

  1. https://stackoverflow.com/questions/49859287/what-is-the-need-of-threading-lock-when-cpython-has-gil
  2. https://stackoverflow.com/questions/40072873/why-do-we-need-locks-for-threads-if-we-have-gil
  3. https://en.wikipedia.org/wiki/Global_interpreter_lock
  4. https://www.zhihu.com/question/23030421/answer/93789486 **通俗解释

  5. https://softwareengineering.stackexchange.com/questions/186889/why-was-python-written-with-the-gil

1. 问题:在CPython中,既然有了GIL,为什么还要lock?

2. 答案:GIL保证了在同一时刻只能有一个线程运行,而lock保证共享数据的安全。lock实现了当某个线程进入临界区时,其他线程必须等待。

以上是 操作系统OS,Python - 有了GIL为什么还要threading.Lock()? 的全部内容, 来源链接: utcz.com/z/388453.html

回到顶部