【发布时间】:2016-09-20 10:12:03
【问题描述】:
Python threading documentation 列出了以下生产者示例:
from threading import Condition
cv = Condition()
# Produce one item
with cv:
make_an_item_available()
cv.notify()
我不得不审查线程,我查看了the C++ documentation, which states:
通知线程不需要在同一个互斥体上持有锁 作为等待线程持有的线程;事实上这样做是一个 悲观化,因为被通知的线程会立即阻塞 再次等待通知线程释放锁。
那建议做这样的事情:
# Produce one item
with cv:
make_an_item_available()
cv.notify()
【问题讨论】:
标签: python multithreading python-multithreading