[Python 3] Condition Variables and Shared Lock. O(N) concurrency
Worst case concurrency over the expensive eating section ==\nO(n/2) == O(n)\n\n\nfrom threading import Condition, Lock\n\nclass DiningPhilosophers:\n    \n    \
Worst case concurrency over the expensive eating section ==\n`O(n/2) == O(n)`\n\n```\nfrom threading import Condition, Lock\n\nclass DiningPhilosophers:\n    \n    \n    def __init__(self):\n        global lock, conds, cond_funcs, forks\n        \n        lock = Lock()\n        conds = [Condition(lock) for _ in range(5)]\n        cond_funcs = [(lambda i=i: forks[i] and forks[(i+1)%5]) for i in range(5)]\n        forks = [True] * 5\n\n\n    def wantsToEat(self,\n                   pid: int,\n                   pickLeftFork: \'Callable[[], None]\',\n                   pickRightFork: \'Callable[[], None]\',\n                   eat: \'Callable[[], None]\',\n                   putLeftFork: \'Callable[[], None]\',\n                   putRightFork: \'Callable[[], None]\') -> None:\n        global lock, conds, cond_funcs, forks\n        \n        \n        with lock:\n            conds[pid].wait_for(cond_funcs[pid])\n            \n            forks[pid] = False\n            forks[(pid+1)%5] = False\n        \n        \n        pickLeftFork()\n        pickRightFork()\n        eat()\n        putRightFork()\n        putLeftFork()\n        \n        \n        with lock:\n            forks[pid] = True\n            forks[(pid+1)%5] = True\n        \n            for PID in (pid-1)%5,pid,(pid+1)%5:\n                conds[PID].notify()\n```
[]