Python solution with 2 semaphores (at most 4 forks picked up to avoid deadlock)
\nfrom threading import Semaphore\nclass DiningPhilosophers(object):\n\n    # call the functions directly to execute, for example, eat()\n    def __init__(self)
```\nfrom threading import Semaphore\nclass DiningPhilosophers(object):\n\n    # call the functions directly to execute, for example, eat()\n    def __init__(self):\n        self.size_lock=Semaphore(4) #at most 4 forks picked up\n        self.locks=[] #semaphore for each single fork\n        for i in range(0,5):\n            self.locks.append(Semaphore(1))\n    def wantsToEat(self, philosopher, pickLeftFork, pickRightFork, eat, putLeftFork, putRightFork):\n        left=philosopher\n        right=(philosopher+4)%5\n\n        self.size_lock.acquire() #2 forks (left and right) once\n        self.size_lock.acquire()\n        \n        self.locks[left].acquire() #left fork\n        self.locks[right].acquire() #right fork\n\t\t\n        pickLeftFork()\n        pickRightFork()\n        eat()\n        putLeftFork()\n        putRightFork()\n\t\t\n        self.locks[left].release()\n        self.locks[right].release()\n        \n        self.size_lock.release()\n        self.size_lock.release()\n```
[]