private static void DiningPhilosophers() { Chopstick c0 = new Chopstick(0); Chopstick c1 = new Chopstick(1); Chopstick c2 = new Chopstick(2); Chopstick c3 = new Chopstick(3); Chopstick c4 = new Chopstick(4); List <Philosopher> philosophers = new List <Philosopher> { new PhilosopherResourceHierarchy("Platon", c4, c0), new PhilosopherResourceHierarchy("Kant", c0, c1), new PhilosopherResourceHierarchy("Sokrates", c1, c2), new PhilosopherResourceHierarchy("Wittgenstein", c2, c3), new PhilosopherResourceHierarchy("Sartre", c3, c4) }; while (true) { string stateString = "|"; foreach (Philosopher p in philosophers) { stateString += p.ToString(); } //Console.Clear(); Console.WriteLine(stateString); Thread.Sleep(100); } }
protected Philosopher(string name, Chopstick left, Chopstick right) { Name = name; Left = left; Right = right; new Thread(() => { Do(); }).Start(); }
public PhilosopherFixed(string name, Chopstick left, Chopstick right) : base(name, left, right) { }
public PhilosopherCentralLock(string name, Chopstick left, Chopstick right) : base(name, left, right) { }
public PhilosopherDeadlock(string name, Chopstick left, Chopstick right) : base(name, left, right) { }
public PhilosopherResourceHierarchy(string name, Chopstick left, Chopstick right) : base(name, left, right) { }