C++17's oneliner solution
This is not the educational type of solution. The trick is to use C++17\'s std::scoped_lock or you may use C++11\'s std::lock.\n\nc++\nclass DiningPhilosophers 
This is not the educational type of solution. The trick is to use C++17\'s `std::scoped_lock` or you may use C++11\'s `std::lock`.\n\n```c++\nclass DiningPhilosophers {\n    array<mutex, 5> mtxs;\npublic:\n    DiningPhilosophers() { }\n    void wantsToEat(int idx,\n                    function<void()> pickLeftFork,\n                    function<void()> pickRightFork,\n                    function<void()> eat,\n                    function<void()> putLeftFork,\n                    function<void()> putRightFork) {\n        scoped_lock(mtxs[idx], mtxs[(idx+1)%5]);\n        pickLeftFork(), pickRightFork(), eat(), putLeftFork(), putRightFork();\n    }\n};\n```
[]