[C++] 132ms/7.2MB using std::condition_variable in a proper way
Example with test cases\nhttps://github.com/jimmy-park/leetcode-cpp-solution/blob/master/Concurrency/1114-Print-in-Order.h\n\n\nclass Foo {\npublic:\n    void f
Example with test cases\nhttps://github.com/jimmy-park/leetcode-cpp-solution/blob/master/Concurrency/1114-Print-in-Order.h\n\n```\nclass Foo {\npublic:\n    void first(function<void()> printFirst)\n    {\n        // printFirst() outputs "first". Do not change or remove this line.\n        printFirst();\n\n        {\n            // prevent lost wakeup and spurious wakeup\n            // and with CTAD (since C++17), you don\'t need to type std::mutex as template argument\n            std::lock_guard lock { mutex_ };\n            done_first_ = true;\n        }\n\n        cv_.notify_all();\n    }\n\n    void second(function<void()> printSecond)\n    {\n        {\n            std::unique_lock lock { mutex_ };\n            cv_.wait(lock, [this] { return done_first_; });\n        }\n\n        // printSecond() outputs "second". Do not change or remove this line.\n        printSecond();\n\n        {\n            std::lock_guard lock { mutex_ };\n            done_second_ = true;\n        }\n        \n        cv_.notify_one();\n    }\n\n    void third(function<void()> printThird)\n    {\n        {\n            std::unique_lock lock { mutex_ };\n            cv_.wait(lock, [this] { return done_second_; });\n        }\n\n        // printThird() outputs "third". Do not change or remove this line.\n        printThird();\n    }\n\nprivate:\n    bool done_first_ { false };\n    bool done_second_ { false };\n    mutable std::mutex mutex_;\n    std::condition_variable cv_;\n};\n```
['C', 'C++']