C++ with 5 mutexes
\nclass DiningPhilosophers {\nprivate:\n    // one mutex per fork\n    std::array<std::mutex, 5> mutexes;\npublic:\n    DiningPhilosophers() {\n        \n    }\
```\nclass DiningPhilosophers {\nprivate:\n    // one mutex per fork\n    std::array<std::mutex, 5> mutexes;\npublic:\n    DiningPhilosophers() {\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        \n        // find the left and right fork numbers\n        int left = philosopher;\n        int right = (philosopher + 1) % 5;\n        \n        // ordered lock to avoid deadlock: fork with min number goes first\n        std::lock_guard<std::mutex> first(mutexes[std::min(left, right)]);\n        std::lock_guard<std::mutex> second(mutexes[std::max(left, right)]);\n        \n        // do the work - fork order does not actualy matter here\n        pickLeftFork(); pickRightFork(); eat(); putRightFork(); putLeftFork();\n    }\n};\n```
[]