| koder aka kdanilov | 4643fd6 | 2015-02-10 16:20:13 -0800 | [diff] [blame] | 1 | import multiprocessing |
| 2 | |||||
| 3 | |||||
| 4 | def get_barrier(count): | ||||
| 5 | val = multiprocessing.Value('i', count) | ||||
| 6 | cond = multiprocessing.Condition() | ||||
| 7 | |||||
| 8 | def closure(timeout): | ||||
| 9 | with cond: | ||||
| 10 | val.value -= 1 | ||||
| 11 | if val.value == 0: | ||||
| 12 | cond.notify_all() | ||||
| 13 | else: | ||||
| 14 | cond.wait(timeout) | ||||
| 15 | return val.value == 0 | ||||
| 16 | |||||
| 17 | return closure | ||||