Python 3 - Semaphore
\nfrom threading import Semaphore\n\nclass FooBar:\n    def __init__(self, n):\n        self.n = n\n        self.foosema = Semaphore(1)\n        self.barsema = 
```\nfrom threading import Semaphore\n\nclass FooBar:\n    def __init__(self, n):\n        self.n = n\n        self.foosema = Semaphore(1)\n        self.barsema = Semaphore(0)\n\n    def foo(self, printFoo):\n        for i in range(self.n):\n            self.foosema.acquire()\n            printFoo()\n            self.barsema.release()\n\n    def bar(self, printBar):\n        for i in range(self.n):\n            self.barsema.acquire()\n            printBar()\n            self.foosema.release()\n```
[]