C++ || Using 5 binary semaphores
```cpp\n#include \nclass DiningPhilosophers {\npublic:\n    vectorv;\n    DiningPhilosophers() {\n        v.resize(5);\n        for(int i=0;i<5;i++) sem_init(&v
```cpp\n#include <semaphore.h>\nclass DiningPhilosophers {\npublic:\n    vector<sem_t>v;\n    DiningPhilosophers() {\n        v.resize(5);\n        for(int i=0;i<5;i++) sem_init(&v[i],0,1);  \n    }\n    ~DiningPhilosophers(){\n        for(int i=0;i<5;i++) sem_destroy(&v[i]);\n    }\n\t//to avoid deadlock, every odd philosopher picks up the left fork first, and every even philosopher picks up the right fork first.\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        int left=philosopher;\n        int right=(philosopher+1)%5;\n        if(philosopher&1){\n            sem_wait(&v[left]);\n            sem_wait(&v[right]);\n        }\n        else{\n            sem_wait(&v[right]);\n            sem_wait(&v[left]);\n        }\n        pickLeftFork();\n        pickRightFork();\n        eat();\n        putLeftFork();\n        putRightFork();\n        sem_post(&v[left]);\n        sem_post(&v[right]);\n    }\n};
[]