C++11 Clean Solution With std::condition_variable and std::mutex
\nclass DiningPhilosophers {\npublic:\n    std::mutex mutex;\n    std::condition_variable cond;\n    vector<int> isvalid;\n    static constexpr int N = 5;\n    
```\nclass DiningPhilosophers {\npublic:\n    std::mutex mutex;\n    std::condition_variable cond;\n    vector<int> isvalid;\n    static constexpr int N = 5;\n    DiningPhilosophers() {\n        isvalid.resize(N, 1);\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            std::unique_lock<std::mutex> lk(mutex);\n            cond.wait(lk, [this, philosopher]() { \n                return isvalid[philosopher] && isvalid[(philosopher + 1) % N]; \n            });\n            isvalid[philosopher] = 0; isvalid[(philosopher + 1) % N] = 0;\n            pickLeftFork(); pickRightFork();\n        }\n        \n        eat();\n        \n        {\n            std::unique_lock<std::mutex> lk(mutex);\n            putLeftFork(); putRightFork();\n            isvalid[philosopher] = 1; isvalid[(philosopher + 1) % N] = 1;\n            cond.notify_all();\n        }\n    }\n};\n```
[]