Python with one Barrier
Intuition\nOne Barrier should be enough to synch each iteration\n\n# Approach\nUse single barrier to sync AFTER foo and BEFORE the bar in each iteration on both
# Intuition\nOne Barrier should be enough to synch each iteration\n\n# Approach\nUse single barrier to sync AFTER foo and BEFORE the bar in each iteration on both threads.\n\nIf you like it, plese up-vote. Thank you!\n\n\n# Code\n```\nfrom threading import Event, Barrier\n\nclass FooBar:\n    def __init__(self, n):\n        self.n = n\n        self.canBar = Barrier(2)  # two parties involved\n\n    def foo(self, printFoo: \'Callable[[], None]\') -> None:\n        for i in range(self.n):\n            # printFoo() outputs "foo". Do not change or remove this line.\n            printFoo()\n            self.canBar.wait()  # we both sync here\n\n    def bar(self, printBar: \'Callable[[], None]\') -> None:\n        for i in range(self.n):\n            self.canBar.wait()  # we both sync here\n            # printBar() outputs "bar". Do not change or remove this line.\n            printBar()\n            self.canBar.reset()  # replay the sync game\n\n```
['Concurrency', 'Python', 'Python3']