[C++]Simple solution using mutex.
I am a newbie about concurrency. Is this right way?\n\n# Code\n\n\n\nclass Foo {\nprivate:\n    mutex task1, task2;\npublic:\n    Foo() {\n        task1.lock();
I am a newbie about concurrency. Is this right way?\n\n# Code\n```\n\n\nclass Foo {\nprivate:\n    mutex task1, task2;\npublic:\n    Foo() {\n        task1.lock();\n        task2.lock();\n    }\n\n    void first(function<void()> printFirst) {\n        \n        // printFirst() outputs "first". Do not change or remove this line.\n        printFirst();\n\n        task1.unlock();\n    }\n\n    void second(function<void()> printSecond) {\n        task1.lock();\n\n        // printSecond() outputs "second". Do not change or remove this line.\n        printSecond();\n\n        task2.unlock();\n    }\n\n    void third(function<void()> printThird) {\n        task2.lock();\n\n        // printThird() outputs "third". Do not change or remove this line.\n        printThird();\n    }\n};\n```
['C++']