MCPcopy Index your code
hub / github.com/RustPython/RustPython / Barrier

Class Barrier

Lib/test/test_thread.py:157–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155
156
157class Barrier:
158 def __init__(self, num_threads):
159 self.num_threads = num_threads
160 self.waiting = 0
161 self.checkin_mutex = thread.allocate_lock()
162 self.checkout_mutex = thread.allocate_lock()
163 self.checkout_mutex.acquire()
164
165 def enter(self):
166 self.checkin_mutex.acquire()
167 self.waiting = self.waiting + 1
168 if self.waiting == self.num_threads:
169 self.waiting = self.num_threads - 1
170 self.checkout_mutex.release()
171 return
172 self.checkin_mutex.release()
173
174 self.checkout_mutex.acquire()
175 self.waiting = self.waiting - 1
176 if self.waiting == 0:
177 self.checkin_mutex.release()
178 return
179 self.checkout_mutex.release()
180
181
182class BarrierTest(BasicThreadTest):

Callers 1

test_barrierMethod · 0.70

Calls

no outgoing calls

Tested by 1

test_barrierMethod · 0.56