[C++] Simple explanation with mutex and semaphore
We can use an array of forks. Set and Unset based on who is using. \n\n\nclass DiningPhilosophers {\npublic:\n    \n    mutex mx;\n    condition_variable cv;\n 
We can use an array of forks. Set and Unset based on who is using. \n\n```\nclass DiningPhilosophers {\npublic:\n    \n    mutex mx;\n    condition_variable cv;\n    vector<int> forks;         \n    int n = 0;\n    \n    \n    DiningPhilosophers() {\n        n = 5;                              \n        forks.resize(n, 0);\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\t\t\n        unique_lock<mutex> lck(mx);\n        \n        int *leftFork = NULL;\n        int *rightFork = NULL;\n        \n        //  GET THE FORKS THAT ARE BESIDE THE PHILOSOPHER. CIRLCE AROUND WHEN REACHING THE LIMITS. \n        if(philosopher == 0)                            \n            leftFork = &forks[n-1];\n        else\n           leftFork = &forks[philosopher -1];\n        \n        if(philosopher == n-1)                      \n            rightFork= &forks[0];\n        else\n            rightFork = &forks[philosopher+1];\n\n        // WAIT UNTIL THE FORKS ARE AVAILABLE\n        while(*leftFork != 0 || *rightFork != 0)            \n            cv.wait(lck);       \n           \n        // SET THE FORKS. \n        *leftFork = 1;\n        *rightFork = 1;\n    \n        pickLeftFork();\n        pickRightFork();\n     \n        eat();\n        \n        putLeftFork();\n        putRightFork();\n        // UNSET THE FORKS. \n        *leftFork = 0;\n        *rightFork = 0;\n\n        cv.notify_all();\n \n    }\n};\n```
[]