C++ solution using mutexes and condition variables
\nclass DiningPhilosophers {\nprivate:\n    std::mutex m;\n    vector<std::condition_variable> cond;\n    vector<bool> isForkAvailable;\n    \npublic:\n    Dini
```\nclass DiningPhilosophers {\nprivate:\n    std::mutex m;\n    vector<std::condition_variable> cond;\n    vector<bool> isForkAvailable;\n    \npublic:\n    DiningPhilosophers() : cond(5){\n        for(int i = 0; i < 5; i++){\n            isForkAvailable.push_back(true);\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        int rightFork = philosopher;\n        int leftFork = philosopher - 1;\n        if(leftFork < 0){\n            leftFork += 5;\n        }\n        int prevPhilosopher = philosopher - 1;\n        if(prevPhilosopher < 0){\n            prevPhilosopher += 5;\n        }\n        int nextPhilosopher = philosopher + 1;\n        nextPhilosopher %= 5;\n\n        {\n            std::unique_lock<std::mutex> lck(m);\n            cond[philosopher].wait(lck, [this, leftFork, rightFork](){\n                return isForkAvailable[leftFork] && isForkAvailable[rightFork];\n            });\n            pickLeftFork();\n            pickRightFork();\n            isForkAvailable[leftFork] = false;\n            isForkAvailable[rightFork] = false;\n        }\n        eat();\n        {\n            std::unique_lock<std::mutex> lck(m);\n            putLeftFork();\n            putRightFork();\n            isForkAvailable[leftFork] = true;\n            isForkAvailable[rightFork] = true;\n        }\n        cond[philosopher].notify_one();\n        cond[prevPhilosopher].notify_one();\n        cond[nextPhilosopher].notify_one();   \n    }\n};\n```
[]