C++ with condition variable and mutex
Only need the mutex when we are trying to pick up the fork. Can synchronize both eating and putting forks down. \n\nclass DiningPhilosophers {\nprivate:\n    in
Only need the mutex when we are trying to pick up the fork. Can synchronize both eating and putting forks down. \n```\nclass DiningPhilosophers {\nprivate:\n    int n; \n    vector<bool> isAvaliable; \n    condition_variable cv; \n    mutex m; \n    \npublic:\n    DiningPhilosophers() {\n        n = 5; \n        isAvaliable.assign(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        {\n            unique_lock<mutex> lc(m); \n            cv.wait(lc, [&](){return isAvaliable[philosopher] && isAvaliable[(philosopher+1)%n];}); \n            isAvaliable[philosopher] = false; \n            isAvaliable[(philosopher+1)%n] = false; \n            pickLeftFork(); \n            pickRightFork(); \n        }\n        eat();  \n        putRightFork(); \n        putLeftFork(); \n        isAvaliable[philosopher] = true; \n        isAvaliable[(philosopher+1)%n] = true; \n        cv.notify_all(); \n\t\t\n    }\n};\n```
[]