public IEnumerable <string> GetDiningPhilosophers() { IOutputter outputter = new EnumerableStringOutputter(); DiningPhilosopher.Start(5, 2, outputter); return(((EnumerableStringOutputter)outputter).Dump()); }
static void Main(string[] args) { IOutputter outputter = new ConsoleOutputter(); ///DiningPhilosopher.Start(5, outputter); ///Console.ReadKey(false); DiningPhilosopher.Start(5, 3, outputter); Console.WriteLine("\nPress any key to exit."); }
public void Run() { Console.WriteLine($"1. Dining Philosopher"); Console.WriteLine($"2. Reader-Writer Lock"); Console.WriteLine($"3. Producer-Consumer"); Console.WriteLine($"4. Sleeping barber"); Console.Write($"Enter choice: "); int choice = Int32.Parse(Console.ReadLine() ?? throw new InvalidOperationException()); switch (choice) { case 1: DiningPhilosopher dp = new DiningPhilosopher(); dp.Start(); break; case 2: DataBase db = new DataBase(); Reader r1 = new Reader(1, db); Writer w1 = new Writer(1, db); Task t1 = Task.Factory.StartNew(() => r1.Run()); Task t2 = Task.Factory.StartNew(() => w1.Run()); Task.WaitAll(t1, t2); break; case 3: Pipe p = new Pipe(); Producer pr = new Producer(p); Consumer cn = new Consumer(p); t1 = Task.Factory.StartNew(() => pr.Run()); t2 = Task.Factory.StartNew(() => cn.Run()); Task.WaitAll(t1, t2); break; case 4: SleepingBarber sb = new SleepingBarber(); sb.Run(); break; default: throw new InvalidOperationException("No choice match found"); } }