C++ solution using mutex and condition_variablec
\nclass DiningPhilosophers {\nprivate:\n    mutex m;\n    condition_variable c;\n    vector<bool> fork;\npublic:\n    DiningPhilosophers(){\n        for(int i =
```\nclass DiningPhilosophers {\nprivate:\n    mutex m;\n    condition_variable c;\n    vector<bool> fork;\npublic:\n    DiningPhilosophers(){\n        for(int i = 0; i < 5; i++){\n            fork.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            unique_lock<mutex> ul(m);\n            c.wait(ul, [&](){\n                return fork[philosopher] && fork[(philosopher + 1) % 5]; \n            });\n            pickLeftFork();\n            pickRightFork();\n            fork[philosopher] = false;\n            fork[(philosopher + 1) % 5] = false;\n        }\n        eat();\n\t\t{\n            lock_guard<mutex> lg(m);\n            putLeftFork();\n            putRightFork();\n            fork[philosopher] = true;\n            fork[(philosopher + 1) % 5] = true;\n        }\n        c.notify_all();\n    }\n};\n```
['Concurrency', 'C++']