C++ || SEMAPHORE || EXTREMELY SHORT ANSWER || EXPLANATION GIVEN
\n#include <semaphore.h>\nclass FooBar {\nprivate:\n    int n;\n    sem_t f;\n    sem_t b;\n\npublic:\n    FooBar(int n) {\n        this->n = n;\n        sem_in
```\n#include <semaphore.h>\nclass FooBar {\nprivate:\n    int n;\n    sem_t f;\n    sem_t b;\n\npublic:\n    FooBar(int n) {\n        this->n = n;\n        sem_init(&f, 0, 1); //foo goes first, so this is set to true\n        sem_init(&b, 0, 0); //bar comes later, so init as false.\n    }\n\n    void foo(function<void()> printFoo) {\n        \n        for (int i = 0; i < n; i++) {\n            sem_wait(&f); //wait for bar, or first time straight come in to print\n        \tprintFoo();\n            sem_post(&b); //afer print foo, then print bar\n        }\n    }\n\n    void bar(function<void()> printBar) {\n        \n        for (int i = 0; i < n; i++) {\n            sem_wait(&b); //wait for foo\n        \tprintBar();\n            sem_post(&f); //after print bar then print foo\n        }\n    }\n};\n\n\n\n```
['C']