Condition Variables
Code\npython3 []\nfrom threading import Condition\n\nclass ZeroEvenOdd:\n    def __init__(self, n):\n        self.n = n\n        self.exec_cond = Condition()\n 
# Code\n```python3 []\nfrom threading import Condition\n\nclass ZeroEvenOdd:\n    def __init__(self, n):\n        self.n = n\n        self.exec_cond = Condition()\n        self.order = 0\n        self.turn = 1\n        \n\t# printNumber(x) outputs "x", where x is an integer.\n    def zero(self, printNumber: \'Callable[[int], None]\') -> None:\n        for _ in range(self.n):\n            with self.exec_cond:\n                self.exec_cond.wait_for(lambda: self.order == 0)\n                printNumber(0)\n                if self.turn & 1:\n                    self.order = 1\n                else:\n                    self.order = 2\n                self.exec_cond.notify_all()\n        \n        \n    def even(self, printNumber: \'Callable[[int], None]\') -> None:\n        for i in range(2, self.n + 1, 2):\n            with self.exec_cond:\n                self.exec_cond.wait_for(lambda : self.order == 2)\n                printNumber(i)\n                self.order = 0\n                self.turn += 1\n                self.exec_cond.notify_all()\n    \n        \n    def odd(self, printNumber: \'Callable[[int], None]\') -> None:\n        for i in range(1, self.n + 1, 2):\n            with self.exec_cond:\n                self.exec_cond.wait_for(lambda : self.order == 1)\n                printNumber(i)\n                self.order = 0\n                self.turn += 1\n                self.exec_cond.notify_all()\n        \n```
['Python3']