c++ using semaphores - short with comments
\n#include <semaphore.h>\nclass Foo {\n    sem_t firstSem;\n    sem_t secondSem;\npublic:\n    Foo() {\n\t//init two semaphores with counter = 0\n        sem_in
```\n#include <semaphore.h>\nclass Foo {\n    sem_t firstSem;\n    sem_t secondSem;\npublic:\n    Foo() {\n\t//init two semaphores with counter = 0\n        sem_init(&firstSem, 0, 0);\n        sem_init(&secondSem, 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(&firstSem); //increase firstSem counter to one to indicate printFirst() was finish \n    }\n\n    void second(function<void()> printSecond) {\n        sem_wait(&firstSem); //wait for printFirst() to finish\n        // printSecond() outputs "second". Do not change or remove this line.\n        printSecond();\n        sem_post(&secondSem);  //increase secondSem counter to one to indicate printSecond() was finish \n    }\n\n    void third(function<void()> printThird) {\n         sem_wait(&secondSem); //wait for printSecond() to finish\n        // printThird() outputs "third". Do not change or remove this line.\n        printThird();\n    }\n};\n```
['C']