Solving Dining philosophers problem
Use python3.9
. There are no other requirements.
import logging
# import required solution class and `start_dinner` executor
from app import start_dinner
from app.tables import Table
# setup logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s",
)
# pass chosen solution class to the executor
start_dinner(Table)
Every philosopher took the left fork and then will forever await for the right fork.
Class Table
Philosopher try to take both forks and if it's not successful - release acquired forks.
Class: TableWithSmartPhilosophers
Let's add waiter. Philosopher can't get fork without waiter. Waiter is a Semaphore with n-1 limit.
Class: TableWithWaiter
Let Philosopher take fork with smaller ID first.
Class: TableWithNumberedForks
Feel free to contribute your solution.