Python with two Events
Intuition\nTwo events: "ready for foo" and "ready for bar". \n\n# Approach\nCreate two events. Just set and clear each in proper moment.\nSee the comments in th
# Intuition\nTwo events: "ready for foo" and "ready for bar". \n\n# Approach\nCreate two events. Just set and clear each in proper moment.\nSee the comments in the code.\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 = Event()\n        self.canBar.clear()  # not yet ready for bar\n        self.canFoo = Event()\n        self.canFoo.set()  # ready for foor\n\n\n    def foo(self, printFoo: \'Callable[[], None]\') -> None:\n        for i in range(self.n):\n            self.canFoo.wait()  # wait until ready for foo\n            # printFoo() outputs "foo". Do not change or remove this line.\n            printFoo()\n            self.canFoo.clear()  # that foo is printed\n            self.canBar.set()  # now, ready for bar\n\n\n    def bar(self, printBar: \'Callable[[], None]\') -> None:\n        for i in range(self.n):\n            self.canBar.wait()  # wait until ready for bar         \n            # printBar() outputs "bar". Do not change or remove this line.\n            printBar()\n            self.canBar.clear()  # that bar is printed\n            self.canFoo.set()  # now, ready for foo\n```
['Concurrency', 'Python', 'Python3']