Dining philosophy scenario?
It's a metaphor for us to study concurrency issues (like deadlock, starvation, livelock, etc) and possible solutions.
Issues
Deadlock
If each one gets hungry in the same time, each one will grab the left fork in the same time, and no one will be able to eat since they won't be able to grab the right fork. All of them will be waiting indefinitely for the right fork which will never be available.
Starvation
Considering that we add one specification to solve the deadlock issue - instead of "If one fork is not available, the philosopher waits until it is available", we can say "If one fork is not available, the philosopher returns the left fork and thinks for a specific X time to try to eat again". Then we could have a philosopher starving if every time he/she tries to eat, one fork (left or right) is not available.
Possible solution
We could bring a waiter that knows when the philosophers are hungry, and knows who has priority, how much each one needs to eat, who has being waiting for a longer time etc. The philosophers will have to request the waiter for a fork then, instead of grabing them off the table.
It's a metaphor for us to study concurrency issues (like deadlock, starvation, livelock, etc) and possible solutions.
Imagine 5 philosophers (the concurrent processes or threads) sitting at a table that has a bowl with 'infinite' supply of spaghetti (the shared resources) and 5 forks, 1 between each pair of philosophers. They don't communicate between themselves and all they do is eating (using the resources) or thinking (not using the resources). When they are hungry, they need to grab the left fork (if it is free), then the right one (if it is also free), then eat. When done eating, they put the forks back to the table. If one fork is not available, the philosopher waits until it is available.
Dining philosophers
Issues
Deadlock
If each one gets hungry in the same time, each one will grab the left fork in the same time, and no one will be able to eat since they won't be able to grab the right fork. All of them will be waiting indefinitely for the right fork which will never be available.
Starvation
Considering that we add one specification to solve the deadlock issue - instead of "If one fork is not available, the philosopher waits until it is available", we can say "If one fork is not available, the philosopher returns the left fork and thinks for a specific X time to try to eat again". Then we could have a philosopher starving if every time he/she tries to eat, one fork (left or right) is not available.
Possible solution
We could bring a waiter that knows when the philosophers are hungry, and knows who has priority, how much each one needs to eat, who has being waiting for a longer time etc. The philosophers will have to request the waiter for a fork then, instead of grabing them off the table.
No comments:
Post a Comment
Please, before starting to comment, evaluate if what you want to write is useful, respectful and positive. A kid may read this also.
Give a good example!