[C++] three versions: condition variables, semaphores, simple bools [fastest 124ms]
Version 1: One mutex lock + two condition variables\n 124 ms\n faster than 89.41%\n\nclass Foo {\npublic:\n    bool firstRan = false;\n    bool secondRan = fals
Version 1: One mutex lock + two condition variables\n* 124 ms\n* faster than 89.41%\n```\nclass Foo {\npublic:\n    bool firstRan = false;\n    bool secondRan = false;\n    pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;\n    pthread_cond_t cv1 = PTHREAD_COND_INITIALIZER;\n    pthread_cond_t cv2 = PTHREAD_COND_INITIALIZER;\n\t\n    Foo() { }\n\n    void first(function<void()> printFirst) {\n        // printFirst() outputs "first". Do not change or remove this line.\n        printFirst();\n        \n        pthread_mutex_lock(&m);\n        firstRan = true;\n        pthread_mutex_unlock(&m);\n        pthread_cond_broadcast(&cv1);\n    }\n\n    void second(function<void()> printSecond) {\n        pthread_mutex_lock(&m);\n\t\t\n        while (!firstRan) { \n            pthread_cond_wait(&cv1, &m);\n        }\n\t\t\n        // printSecond() outputs "second". Do not change or remove this line.\n        printSecond();\n        \n        secondRan = true;\n        pthread_mutex_unlock(&m);\n        pthread_cond_broadcast(&cv2);\n    }\n\n    void third(function<void()> printThird) {\n        pthread_mutex_lock(&m);\n\t\t\n        while (!firstRan) {\n             pthread_cond_wait(&cv1, &m);\n        }\n        while (!secondRan) {\n             pthread_cond_wait(&cv2, &m);\n        }\n\t\t\n        // printThird() outputs "third". Do not change or remove this line.\n        printThird();\n        pthread_mutex_unlock(&m);\n    }\n};\n```\n\nVersion 2: Two semaphores\n* 132 ms\n* Faster than 82.37%\n```\n#include <semaphore.h>\n\nclass Foo {\npublic:\n    sem_t s1;\n    sem_t s2;\n    Foo() {\n        sem_init(&s1, 0, 0);\n        sem_init(&s2, 0, 0);\n    }\n\n    void first(function<void()> printFirst) {\n        // printFirst() outputs "first". Do not change or remove this line.\n        printFirst();\n        sem_post(&s1);\n    }\n\n    void second(function<void()> printSecond) {\n        sem_wait(&s1);\n        // printSecond() outputs "second". Do not change or remove this line.\n        printSecond();\n        sem_post(&s2);\n        \n    }\n\n    void third(function<void()> printThird) {\n        sem_wait(&s2);\n        // printThird() outputs "third". Do not change or remove this line.\n        printThird();\n    }\n};\n```\n\nVersion 3: Simple bools\n* 1400 ms\n* Faster than 8.13%\n```\nclass Foo {\npublic:\n    bool firstRan = false;\n    bool secondRan = false;\n    Foo() { }\n\n    void first(function<void()> printFirst) {\n        // printFirst() outputs "first". Do not change or remove this line.\n        printFirst();\n        \n        firstRan = true;\n    }\n\n    void second(function<void()> printSecond) {\n        while(!firstRan) { }\n        // printSecond() outputs "second". Do not change or remove this line.\n        printSecond();\n        secondRan = true;\n    }\n\n    void third(function<void()> printThird) {\n        while (!(firstRan && secondRan))  { }\n        // printThird() outputs "third". Do not change or remove this line.\n        printThird();\n    }\n};\n```\n\nLet me know if anyone finds better ways to do what I did!
['C']