[C++] Using std::condition_variable
C++\nclass FooBar {\nprivate:\n  int n;\n  bool                    fooTime;\n  std::mutex              mtx;\n  std::condition_variable cv;\n\npublic:\n  FooBar(
```C++\nclass FooBar {\nprivate:\n  int n;\n  bool                    fooTime;\n  std::mutex              mtx;\n  std::condition_variable cv;\n\npublic:\n  FooBar(int n) : n(n), fooTime(true) {}\n  \n  void setFooTime(bool ft, std::unique_lock<std::mutex>& lock) {\n    fooTime = ft;\n    lock.unlock();\n    cv.notify_one();\n    lock.lock();\n  }\n\n  void foo(function<void()> printFoo) {\n    std::unique_lock<std::mutex> lock(mtx);\n    for (int i = 0; i < n; i++) {\n      cv.wait(lock, [this]{ return fooTime; });\n      printFoo();\n      setFooTime(false, lock);\n    }\n  }\n\n  void bar(function<void()> printBar) {\n    std::unique_lock<std::mutex> lock(mtx);\n    for (int i = 0; i < n; i++) {\n      cv.wait(lock, [this]{ return !fooTime; });\n      printBar();\n      setFooTime(true, lock);\n    }\n  }\n};\n```
['C']