C++ condition variable
class FooBar {\nprivate:\n    int n;\n    std::mutex m;\n    std::condition_variable cv;\n    bool flag = false;\n\npublic:\n    FooBar(int n) {\n        this->
class FooBar {\nprivate:\n    int n;\n    std::mutex m;\n    std::condition_variable cv;\n    bool flag = false;\n\npublic:\n    FooBar(int n) {\n        this->n = n;\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            std::unique_lock<std::mutex> lock(m);\n            cv.wait(lock,[this]{ return !flag;});\n            printFoo();\n            flag = true;\n            cv.notify_one();\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            std::unique_lock<std::mutex> lock(m);\n            cv.wait(lock,[this]{ return flag;});\n        \tprintBar();\n            flag = false;\n            cv.notify_one();\n            \n        }\n    }\n};
[]