C++ mutexes only, even philosophers take left forks first
Even philosophers take left forks first and odd philosophers take right fork first.\n\n    mutex m[5];\n\npublic:\n    DiningPhilosophers() {\n    }\n\n    void
Even philosophers take left forks first and odd philosophers take right fork first.\n```\n    mutex m[5];\n\npublic:\n    DiningPhilosophers() {\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\n        int left = philosopher;\n        int right = (left + 4) % 5;\n        bool even = philosopher % 2 == 0;\n        int first = even ? left : right;\n        int second = left + right - first;\n\n        unique_lock<mutex> lock1(m[first]);\n        unique_lock<mutex> lock2(m[second]);\n\n        pickLeftFork();\n        pickRightFork();\n        eat();\n        putLeftFork();\n        putRightFork();\n    }\n```
[]