C++ MUTEX AND CONDITION VARIABLE 12MS
\nclass Foo {\n    mutex m;\n    condition_variable firstCond;\n    condition_variable secondCond;\n    condition_variable thirdCond;\n    int chance;\npublic:\
```\nclass Foo {\n    mutex m;\n    condition_variable firstCond;\n    condition_variable secondCond;\n    condition_variable thirdCond;\n    int chance;\npublic:\n    Foo() {\n        chance=1;\n    }\n\n    void first(function<void()> printFirst) {\n        unique_lock<mutex> locker(m);\n        \n        firstCond.wait(locker,[&](){\n            return chance==1;\n        });\n        \n        // printFirst() outputs "first". Do not change or remove this line.\n        printFirst();\n        \n        chance=2;\n        secondCond.notify_one();\n    }\n\n    void second(function<void()> printSecond) {\n        unique_lock<mutex> locker(m);\n        \n        secondCond.wait(locker,[&](){\n            return chance==2;\n        });\n        \n        // printSecond() outputs "second". Do not change or remove this line.\n        printSecond();\n        \n        chance=3;\n        thirdCond.notify_one();\n    }\n\n    void third(function<void()> printThird) {\n        unique_lock<mutex> locker(m);\n        \n        thirdCond.wait(locker,[&](){\n            return chance==3;\n        });\n        \n        // printThird() outputs "third". Do not change or remove this line.\n        printThird();\n    }\n};\n```
[]