C++ Simplest Solution Using Semaphores
\n#include <semaphore.h>\n\nclass DiningPhilosophers {\npublic:\n    DiningPhilosophers() {\n        for (int i=0; i<5; i++) {\n            sem_t s;\n          
```\n#include <semaphore.h>\n\nclass DiningPhilosophers {\npublic:\n    DiningPhilosophers() {\n        for (int i=0; i<5; i++) {\n            sem_t s;\n            sem_init(&s, 0, 1);\n            m_forks.push_back(s);\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        //wait till left fork is available\n\t\tsem_wait(&m_forks[philosopher]);\n        pickLeftFork();\n        \n        //wait till right fork is available\n        sem_wait(&m_forks[(philosopher+1)%5]);\n        pickRightFork();\n        \n        eat();\n        \n        putLeftFork();\n        sem_post(&m_forks[philosopher]);\n        \n        putRightFork();\n        sem_post(&m_forks[(philosopher+1)%5]);\n    }\nprivate:\n    vector<sem_t> m_forks;\n};\n```\n**Like it? please upvote...**
['C']