C++; 5 mutexes and a scoped_lock; Too simple to believe it would be accepted.
It looks like the deadlock avoidance algorithm that comes with the std::scoped_lock is sufficient for this problem. Pick up the forks only if both forks are ava
It looks like the deadlock avoidance algorithm that comes with the std::scoped_lock is sufficient for this problem. Pick up the forks only if both forks are available.\n```\nclass DiningPhilosophers {\n    array<mutex, 5> m;\npublic:\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\t\tscoped_lock lck{m[philosopher], m[(philosopher + 1) % 5]};\n        pickLeftFork();\n        pickRightFork();\n        eat();\n        putLeftFork();\n        putRightFork();\n    }\n};\n```
[]