C++ using semaphore.h
\n#include <semaphore.h>\n\nclass ZeroEvenOdd {\nprivate:\n    int n;\n    \n    sem_t zero_sem;\n    sem_t odd_sem;\n    sem_t even_sem;\n\npublic:\n    ZeroEv
```\n#include <semaphore.h>\n\nclass ZeroEvenOdd {\nprivate:\n    int n;\n    \n    sem_t zero_sem;\n    sem_t odd_sem;\n    sem_t even_sem;\n\npublic:\n    ZeroEvenOdd(int n) {\n        this->n = n;  \n        sem_init(&zero_sem, 0, 1);\n        sem_init(&odd_sem, 0, 0);\n        sem_init(&even_sem, 0, 0);  \n    }\n    \n    ~ZeroEvenOdd() {\n        sem_destroy(&zero_sem);\n        sem_destroy(&odd_sem);\n        sem_destroy(&even_sem);  \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            sem_wait(&zero_sem);\n            printNumber(0);\n            if (i & 1) sem_post(&odd_sem);\n            else sem_post(&even_sem);\n        }\n    }\n\n    void even(function<void(int)> printNumber) {\n        for (int i = 2; i <= n; i+=2) {\n            sem_wait(&even_sem);\n            printNumber(i);\n            sem_post(&zero_sem);\n        }   \n    }\n\n    void odd(function<void(int)> printNumber) {\n        for (int i = 1; i <= n; i+=2) {\n            sem_wait(&odd_sem);        \n            printNumber(i);\n            sem_post(&zero_sem);\n        }    \n    }\n};\n```
[]