C++ SOLUTION
Code\n\nclass Semaphore{\n    mutex m;\n    condition_variable cv;\n    int cnt;\npublic:\n    Semaphore(){}\n    Semaphore(int c):cnt(c){};\n    void setCount(
# Code\n```\nclass Semaphore{\n    mutex m;\n    condition_variable cv;\n    int cnt;\npublic:\n    Semaphore(){}\n    Semaphore(int c):cnt(c){};\n    void setCount(int a){\n        cnt=a;\n    }\n    inline void signal(){\n        unique_lock<mutex> lock(m);\n        cnt++;\n        if(cnt<=0) cv.notify_all();\n    }\n    inline void wait(){\n        unique_lock<mutex> lock(m);\n        cnt--;\n        while(cnt<0) cv.wait(lock);\n    }\n};\nclass DiningPhilosophers {\n    Semaphore fork[5];\n    mutex m;\npublic:\n    DiningPhilosophers() {\n        for(int i=0;i<5;i++){\n            fork[i].setCount(1);\n        }\n    }\n\n    void wantsToEat(int philosopher,function<void()> pickLeftFork,function<void()> pickRightFork,function<void()> eat,function<void()> putLeftFork,function<void()> putRightFork) {\n        lock_guard<mutex> lock(m);\n        fork[(philosopher+1)%5].wait();\n        fork[philosopher].wait();\n        pickLeftFork();\n        pickRightFork();\n        eat();\n        putLeftFork();\n        fork[(philosopher+1)%5].signal();\n        putRightFork();\n        fork[philosopher].signal();\n    }\n};\n```
['C++']