C++ Solution Using 2 mutexes
\nclass Foo {\npublic:\n    Foo() {\n        pthread_mutex_lock(&m_second);\n        pthread_mutex_lock(&m_third);\n    }\n    \n    ~Foo() {\n        pthread_m
```\nclass Foo {\npublic:\n    Foo() {\n        pthread_mutex_lock(&m_second);\n        pthread_mutex_lock(&m_third);\n    }\n    \n    ~Foo() {\n        pthread_mutex_destroy(&m_second);\n        pthread_mutex_destroy(&m_third);\n    }\n\n    void first(function<void()> printFirst) {\n        \n        // printFirst() outputs "first". Do not change or remove this line.\n        printFirst();\n        pthread_mutex_unlock(&m_second);\n    }\n\n    void second(function<void()> printSecond) {\n        \n        // printSecond() outputs "second". Do not change or remove this line.\n        pthread_mutex_lock(&m_second);\n        printSecond();\n        pthread_mutex_unlock(&m_third);\n    }\n\n    void third(function<void()> printThird) {\n        \n        // printThird() outputs "third". Do not change or remove this line.\n        pthread_mutex_lock(&m_third);\n        printThird();\n    }\nprivate:\n    pthread_mutex_t m_second = PTHREAD_MUTEX_INITIALIZER;\n    pthread_mutex_t m_third = PTHREAD_MUTEX_INITIALIZER;\n};\n```
[]