c++ semaphore
\n#include<semaphore.h>\nclass FooBar {\nprivate:\n    int n;\n\tsem_t s1,s2;\n\npublic:\n    FooBar(int n) {\n        this->n = n;\n        sem_init(&s1,0,0);\
```\n#include<semaphore.h>\nclass FooBar {\nprivate:\n    int n;\n\tsem_t s1,s2;\n\npublic:\n    FooBar(int n) {\n        this->n = n;\n        sem_init(&s1,0,0);\n        sem_init(&s2,0,1);\n    }\n\n    void foo(function<void()> printFoo) {\n        \n        for (int i = 0; i < n; i++) {\n            sem_wait(&s2);\n        \t// printFoo() outputs "foo". Do not change or remove this line.\n        \tprintFoo();\n            sem_post(&s1);\n        }\n    }\n\n    void bar(function<void()> printBar) {\n        \n        for (int i = 0; i < n; i++) {\n            sem_wait(&s1);\n        \t// printBar() outputs "bar". Do not change or remove this line.\n        \tprintBar();\n            sem_post(&s2);\n        }\n    }\n};\n```
['C']