示例#1
0
        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);
            }
        }
示例#2
0
        protected Philosopher(string name, Chopstick left, Chopstick right)
        {
            Name  = name;
            Left  = left;
            Right = right;


            new Thread(() => { Do(); }).Start();
        }
示例#3
0
 public PhilosopherFixed(string name, Chopstick left, Chopstick right)
     : base(name, left, right)
 {
 }
 public PhilosopherCentralLock(string name, Chopstick left, Chopstick right)
     : base(name, left, right)
 {
 }
示例#5
0
 public PhilosopherDeadlock(string name, Chopstick left, Chopstick right)
     : base(name, left, right)
 {
 }
 public PhilosopherResourceHierarchy(string name, Chopstick left, Chopstick right)
     : base(name, left, right)
 {
 }