| 347 | |
| 348 | |
| 349 | class 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 | |
| 374 | class BarrierTest(BasicThreadTest): |
no outgoing calls
searching dependent graphs…