Starvation here is because of a philosopher acquiring a left-hand side chopstick and waiting for a right-hand side chopstick which is acquired by another philosopher on its left and is waiting for its right. This is resolved first by using synchronised keyword to ensure that only one philosopher can acquire a chopstick at a time (mutual-exclusion) and then breaking the circular dependency in acquiring chopsticks by ensuring one philosopher acquires it's first chopstick in a way different than the others, i.e. If other choose their first chopstick in left, then he must decide his first on its right.
After 6 years of using java first time, I got a clear vision for concurrency. it's really a great playlist.thank yooooooou
But how does this solution avoid starvation of a particular philosopher?
Starvation here is because of a philosopher acquiring a left-hand side chopstick and waiting for a right-hand side chopstick which is acquired by another philosopher on its left and is waiting for its right.
This is resolved first by using synchronised keyword to ensure that only one philosopher can acquire a chopstick at a time (mutual-exclusion) and then breaking the circular dependency in acquiring chopsticks by ensuring one philosopher acquires it's first chopstick in a way different than the others, i.e. If other choose their first chopstick in left, then he must decide his first on its right.