MCPcopy Index your code
hub / github.com/python/cpython / Barrier

Class Barrier

Lib/test/test_thread.py:349–371  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

347
348
349class Barrier:
350 def __init__(self, num_threads):
351 self.num_threads = num_threads
352 self.waiting = 0
353 self.checkin_mutex = thread.allocate_lock()
354 self.checkout_mutex = thread.allocate_lock()
355 self.checkout_mutex.acquire()
356
357 def enter(self):
358 self.checkin_mutex.acquire()
359 self.waiting = self.waiting + 1
360 if self.waiting == self.num_threads:
361 self.waiting = self.num_threads - 1
362 self.checkout_mutex.release()
363 return
364 self.checkin_mutex.release()
365
366 self.checkout_mutex.acquire()
367 self.waiting = self.waiting - 1
368 if self.waiting == 0:
369 self.checkin_mutex.release()
370 return
371 self.checkout_mutex.release()
372
373
374class BarrierTest(BasicThreadTest):

Callers 1

test_barrierMethod · 0.70

Calls

no outgoing calls

Tested by 1

test_barrierMethod · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…