C++ EASY AND CLEAN SOLUTION
Code\n\nclass ZeroEvenOdd {\nprivate:\n    int n;\n    mutex m0,me,mo;\npublic:\n    ZeroEvenOdd(int n) {\n        this->n = n;\n        me.lock();\n        mo.
# Code\n```\nclass ZeroEvenOdd {\nprivate:\n    int n;\n    mutex m0,me,mo;\npublic:\n    ZeroEvenOdd(int n) {\n        this->n = n;\n        me.lock();\n        mo.lock();\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            m0.lock();\n            printNumber(0);\n            if(i%2) mo.unlock();\n            else me.unlock();\n        }\n    }\n\n    void even(function<void(int)> printNumber) {\n        for(int i=2;i<=n;i+=2){\n            me.lock();\n            printNumber(i);\n            m0.unlock();\n        }\n    }\n\n    void odd(function<void(int)> printNumber) {\n        for(int i=1;i<=n;i+=2){\n            mo.lock();\n            printNumber(i);\n            m0.unlock();\n        }\n    }\n};\n```
['C++']