C++ solution with mutex and cv
\nclass DiningPhilosophers {\n        static int const N = 5;\n        mutex mtx;\n        condition_variable cv;\n        vector<bool> fork;\npublic:\n    Dini
```\nclass DiningPhilosophers {\n        static int const N = 5;\n        mutex mtx;\n        condition_variable cv;\n        vector<bool> fork;\npublic:\n    DiningPhilosophers(): fork(N, true) {\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        int left = philosopher;\n        int right= philosopher>0? philosopher-1: N-1;\n        {\n            unique_lock<mutex> lock(mtx);\n            cv.wait(lock, [this, left, right]{ return fork[left] && fork[right];});\n            fork[left] = false;\n            fork[right] = false;\n        }\n        \n        pickLeftFork();\n        pickRightFork();\n        eat();\n        putLeftFork();\n        putRightFork();\n        \n        {\n            unique_lock<mutex> lock(mtx);\n            fork[left] = true;\n            fork[right] = true;\n        }\n        cv.notify_all();\n    }\n};\n```
[]