def __init__(self, opt, world):
super().__init__(opt)
self.inner_world = world
self.numthreads = opt['numthreads']
self.sync = { # syncronization primitives
# semaphores for counting queued examples
'queued_sem': Semaphore(0), # counts num exs to be processed
'threads_sem': Semaphore(0), # counts threads
'reset_sem': Semaphore(0), # allows threads to reset
# flags for communicating with threads
'reset_flag': Value('b', False), # threads should reset
'term_flag': Value('b', False), # threads should terminate
# counters
'epoch_done_ctr': Value('i', 0), # number of done threads
'total_parleys': Value('l', 0), # number of parleys in threads
}
# don't let threads create more threads!
self.threads = []
for i in range(self.numthreads):
self.threads.append(HogwildProcess(i, opt, world, self.sync))
for t in self.threads:
t.start()
for _ in self.threads:
self.sync['threads_sem'].acquire()
评论列表
文章目录