[C++] Faster than 98%! 99ms/10.8MB, using mutexes only
\nstatic constexpr uint8_t FORKS_NUM = 5;\nclass DiningPhilosophers {\npublic:\n    DiningPhilosophers() {\n        for(int i = 0; i < FORKS_NUM; ++i){\n       
```\nstatic constexpr uint8_t FORKS_NUM = 5;\nclass DiningPhilosophers {\npublic:\n    DiningPhilosophers() {\n        for(int i = 0; i < FORKS_NUM; ++i){\n            pthread_mutex_init(&forks[i], NULL);\n        }    \n    }\n\n    void wantsToEat(int philosopher,\n                    function<void()> pickLeftFork,\n                    function<void()> pickRightFork,\n                    function<void()> eat,\n                    function<void()> putLeftFork,\n                    function<void()> putRightFork) {\n        uint8_t leftForkId = (philosopher + 1) % FORKS_NUM;\n        uint8_t rightForkId = philosopher;\n        if(philosopher < FORKS_NUM - 1){\n            pthread_mutex_lock(&forks[rightForkId]);\n            pthread_mutex_lock(&forks[leftForkId]);\n        }\n        else{ // this prevents the circular wait condition, that if would happen would cause the deadlock.\n            pthread_mutex_lock(&forks[leftForkId]);\n            pthread_mutex_lock(&forks[rightForkId]);\n        }\n        pickLeftFork();\n        pickRightFork();\n        eat();\n        putLeftFork();\n        pthread_mutex_unlock(&forks[leftForkId]);\n        putRightFork();\n        pthread_mutex_unlock(&forks[rightForkId]);\n    }\nprivate:\n    pthread_mutex_t forks[FORKS_NUM]; // mutex for each fork\n};\n```
['C']