Пример #1
0
        public static void Main()
        {
            int n = 5;

            Chopstick[] cSticks = new Chopstick[n];
            for (int i = 0; i < n; i++)
            {
                cSticks[i] = new Chopstick();
            }
            Philosopher[] philosophers = new Philosopher[n];
            for (int i = 0; i < n; i++)
            {
                philosophers[i] = new Philosopher(cSticks[(n + i - 1) % n], cSticks[i]);
                //Poprawka wprowadzona aby program nie ulegał zakleszczeniu
                if (i == 0)
                {
                    philosophers[i].LeftHanded = true;
                }
                philosophers[i].Start();
            }
        }
Пример #2
0
 public Philosopher(Chopstick lC, Chopstick rC)
 {
     ID             = max_id++;
     leftChopstick  = lC;
     rightChopstick = rC;
 }