C++ clean solution with mutex and condition_variable.
\nclass ZeroEvenOdd {\nprivate:\n    mutex mu;\n    condition_variable cond;\n    size_t state = 0;\n    int n;\n\npublic:\n ZeroEvenOdd(int n) {\n        this-
```\nclass ZeroEvenOdd {\nprivate:\n    mutex mu;\n    condition_variable cond;\n    size_t state = 0;\n    int n;\n\npublic:\n ZeroEvenOdd(int n) {\n        this->n = n;\n    }\n\n    // printNumber(x) outputs "x", where x is an integer.\n    void zero(function<void(int)> printNumber) {\n        for (int i = 1; i <= n; i++) {\n            unique_lock<mutex> lock(mu);\n            cond.wait(lock,[&](){return state==0;});\n            printNumber(0);\n            if (i%2 == 0)\n                state = 2;\n            else\n                state = 1;\n            cond.notify_one();\n        }\n    }\n\n    void even(function<void(int)> printNumber) {\n        for (int i = 2; i <= n; i+= 2) {\n            unique_lock<mutex> lock(mu);\n            cond.wait(lock,[&](){return state==2;});\n            printNumber(i);\n            state = 0;\n            cond.notify_one();\n        }\n    }\n\n    void odd(function<void(int)> printNumber) {\n        for (int i = 1; i <= n; i+= 2) {\n            unique_lock<mutex> lock(mu);\n            cond.wait(lock,[&](){return state==1;});\n            printNumber(i);\n             state = 0;\n             cond.notify_one();\n        }\n    }\n};\n```
[]