[Cpp] Mutex solution
```\nclass FooBar {\n    mutex m1,m2;\nprivate:\n    int n;\n\npublic:\n    FooBar(int n) {\n        this->n = n;\n\t\tm1.lock();\n    }\n\n    void foo(functio
```\nclass FooBar {\n    mutex m1,m2;\nprivate:\n    int n;\n\npublic:\n    FooBar(int n) {\n        this->n = n;\n\t\tm1.lock();\n    }\n\n    void foo(function<void()> printFoo) {\n        \n        for (int i = 0; i < n; i++) {\n            \n        \t// printFoo() outputs "foo". Do not change or remove this line.\n            m2.lock();\n        \tprintFoo();\n            m1.unlock();\n            \n        }\n    }\n\n    void bar(function<void()> printBar) {\n        \n        for (int i = 0; i < n; i++) {\n            \n        \t// printBar() outputs "bar". Do not change or remove this line.\n            m1.lock();\n        \tprintBar();\n            m2.unlock();\n            \n        }\n    }\n};
['C', 'C++']