Partial order - why wrong answer?
Can anybody please help understand why partial order implemented with Semaphore gives Wrong Answer, is it a problem with the test?\n\n\nclass DiningPhilosophers
Can anybody please help understand why partial order implemented with Semaphore gives Wrong Answer, is it a problem with the test?\n\n```\nclass DiningPhilosophers {\n\n    private final Semaphore[] s;\n    public DiningPhilosophers() {\n        s = new Semaphore[5];\n        for (int i = 0 ; i < s.length; i++) {\n            s[i] = new Semaphore(1);            \n        }\n    }\n\n    // call the run() method of any runnable to execute its code\n    public void wantsToEat(int philosopher,\n                           Runnable pickLeftFork,\n                           Runnable pickRightFork,\n                           Runnable eat,\n                           Runnable putLeftFork,\n                           Runnable putRightFork) throws InterruptedException {        \n        int left = philosopher == 0 ? s.length - 1 : philosopher - 1;\n        int right = philosopher;\n        if (left < right) {\n            s[left].acquire();    \n            pickLeftFork.run();\n            \n            s[right].acquire();    \n            pickRightFork.run();        \n\n        } else {\n            s[right].acquire();    \n            pickRightFork.run();        \n            \n            s[left].acquire();    \n            pickLeftFork.run();\n        }\n        \n        eat.run();\n        \n        putLeftFork.run();\n        s[left].release();\n        putRightFork.run();                    \n        s[right].release();        \n    }        \n}\n```
[]