Python有什么样的监视器?

2024-09-27 21:23:26 发布

您现在位置:Python中文网/ 问答频道 /正文

Python有什么样的监视器(并发编程)?Brinch Hansen,Hoare还是Lampson/Redell(像Java)?在

  • brinchhansen:通知线程退出监视器,被通知的线程继续。在
  • Hoare:notifier线程进入一个特殊队列,通知继续。在
  • Lampson/Redell:通知线程继续,被通知的线程进入入口队列。在

Tags: 队列编程java线程notifier监视器hoarehansen
1条回答
网友
1楼 · 发布于 2024-09-27 21:23:26

官方documentation对此给出了答案:

The wait() method releases the lock, and then blocks until it is awakened by a notify() or notifyAll() call for the same condition variable in another thread. Once awakened, it re-acquires the lock and returns. It is also possible to specify a timeout.

The notify() method wakes up one of the threads waiting for the condition variable, if any are waiting. The notifyAll() method wakes up all threads waiting for the condition variable.

Note: the notify() and notifyAll() methods don’t release the lock; this means that the thread or threads awakened will not return from their wait() call immediately, but only when the thread that called notify() or notifyAll() finally relinquishes ownership of the lock.

相关问题 更多 >

    热门问题