should_go = False
cv = Condition()
while True:
with cv:
if not should_go:
cv.wait()
if should_go:
# process_time_cost_tasks()
should_go = False
def request():
with cv:
should_go = True
cv.notify()
问题:如果我在任务处理期间(很长时间)拥有锁定,这是否重要?
答案 0 :(得分:0)
您似乎希望将cv
用作should_go
的互斥锁。 bool
assignment is atomic, so this is not needed.
如果您在询问是否阻止process_time_cost_tasks
内的锁定会阻止request
,它会。这是一个锁定,它是什么。