1116. Print Zero Even Odd | Clean* c++ | unique_lock + condition_variable
\nclass ZeroEvenOdd {\nprivate:\n    int n;\n    int count = 0; // if count is even let zero() print\n    int next = 1; // if odd let odd() print, if even let e
```\nclass ZeroEvenOdd {\nprivate:\n    int n;\n    int count = 0; // if count is even let zero() print\n    int next = 1; // if odd let odd() print, if even let even() print\n    mutex m;\n    condition_variable cv;\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        while(true) {\n            unique_lock<mutex> lk(m);\n            cv.wait(lk, [&]{return count % 2 == 0;});\n            if(count < 2*n) printNumber(0);\n            ++count;\n            lk.unlock();\n            cv.notify_all();\n            if(count >= 2*n) return;\n        }\n    }\n\n    void even(function<void(int)> printNumber) {\n        while(true) {\n            unique_lock<mutex> lk(m);\n            cv.wait(lk, [&]{return count % 2 == 1 && next % 2 == 0;});\n            if(count < 2*n) printNumber(next);\n            ++count;\n            ++next;\n            lk.unlock();\n            cv.notify_all();\n            if(count >= 2*n) return;\n        }\n    }\n\n    void odd(function<void(int)> printNumber) {\n        while(true) {\n            unique_lock<mutex> lk(m);\n            cv.wait(lk, [&]{return count % 2 == 1 && next % 2 == 1;});\n            if(count < 2*n) printNumber(next);\n            ++count;\n            ++next;\n            lk.unlock();\n            cv.notify_all();\n            if(count >= 2*n) return;\n        }\n    }\n};\n```
[]