Python 3 solution using threading.Condition()
The class FooBar is equipped with a threading.Condition() and a flag variable last_printed which is initialized as None. The foo() method waits until last_print
The class `FooBar` is equipped with a `threading.Condition()` and a flag variable `last_printed` which is initialized as `None`. The `foo()` method waits until `last_printed` is either `None` or `\'bar\'`, while the `bar()` method waits until `last_printed` is `\'foo\'` (cf. https://docs.python.org/3/library/threading.html#condition-objects).\n\n```python\nimport threading\nfrom typing import Callable, Optional\n\n\nclass FooBar:\n    def __init__(self, n: int) -> None:\n        self.n = n\n        self.condition = threading.Condition()\n        self.last_printed: Optional[str] = None\n\n    def foo(self, printFoo: Callable[[], None]) -> None:\n        for i in range(self.n):\n            with self.condition:\n                self.condition.wait_for(lambda: self.last_printed in (None, \'bar\'))\n                printFoo()\n                self.last_printed = \'foo\'\n                self.condition.notify()\n\n    def bar(self, printBar: Callable[[], None]) -> None:\n        for i in range(self.n):\n            with self.condition:\n                self.condition.wait_for(lambda: self.last_printed == \'foo\')\n                printBar()\n                self.last_printed = \'bar\'\n                self.condition.notify()\n```
[]