def __init__(self, lock=None):
# the lock actually used by .acquire() and .release()
if lock is None:
self.mutex = thread.allocate_lock()
else:
if hasattr(lock, 'acquire') and \
hasattr(lock, 'release'):
self.mutex = lock
else:
raise TypeError, 'condition constructor requires ' \
'a lock argument'
# lock used to block threads until a signal
self.checkout = thread.allocate_lock()
self.checkout.acquire()
# internal critical-section lock, & the data it protects
self.idlock = thread.allocate_lock()
self.id = 0
self.waiting = 0 # num waiters subject to current release
self.pending = 0 # num waiters awaiting next signal
self.torelease = 0 # num waiters to release
self.releasing = 0 # 1 iff release is in progress
评论列表
文章目录