Use semaphores for C++ solution
\n#include <semaphore.h>\nclass Foo {\nprotected:\n    sem_t firstDone;\n    sem_t secondDone;\npublic:\n    Foo() {\n        sem_init(&firstDone, 0, 0);\n     
```\n#include <semaphore.h>\nclass Foo {\nprotected:\n    sem_t firstDone;\n    sem_t secondDone;\npublic:\n    Foo() {\n        sem_init(&firstDone, 0, 0);\n        sem_init(&secondDone, 0, 0);\n    }\n\n    void first(function<void()> printFirst) {\n        \n        // printFirst() outputs "first". Do not change or remove this line.\n        printFirst();\n        sem_post(&firstDone);\n    }\n\n    void second(function<void()> printSecond) {\n        sem_wait(&firstDone);\n        // printSecond() outputs "second". Do not change or remove this line.\n        printSecond();\n        sem_post(&secondDone);\n    }\n\n    void third(function<void()> printThird) {\n        sem_wait(&secondDone);\n        // printThird() outputs "third". Do not change or remove this line.\n        printThird();\n    }\n};\n```
['C', 'C++']