Beispiel #1
0
        public void RightHandedEaterGetsFood(Philosopher eater, TakeBitEventArgs e)
        {
            eater.RightChopstick.WaitOne();
            eater.LeftChopstick.WaitOne();

            Eat(eater);
            eater.RightChopstick.Set();
            eater.LeftChopstick.Set();
        }
Beispiel #2
0
        private void Eat(Philosopher eater)
        {
            lock (Locker)
            {
                //What if no food is delivered?
                if (Dish.TakeBite())
                {
                    eater.HungerLevel--;

                    Console.WriteLine($"Eater # {eater.Id} takes a bite. Hunger level: {eater.HungerLevel} --- Remainging food: {Dish.Bites}");
                    eater.IsEating = false;
                }
            }
            Monitor.Pulse(Locker);
        }
Beispiel #3
0
        public void RightHandedEaterGetsFood(Philosopher eater, TakeBitEventArgs e)
        {

            eater.RightChopstick.WaitOne();
            eater.LeftChopstick.WaitOne();

            Eat(eater);
            eater.RightChopstick.Set();
            eater.LeftChopstick.Set();



        }
Beispiel #4
0
 protected virtual void OnTakeBiteEvent(Philosopher eater, TakeBitEventArgs e)
 {
     TakeBiteEvent?.Invoke(eater, e);
 }
Beispiel #5
0
        private void Eat(Philosopher eater)
        {
            lock (Locker)
            {
                //What if no food is delivered?
                if (Dish.TakeBite())
                {
                    
                    eater.HungerLevel--;

                    Console.WriteLine($"Eater # {eater.Id} takes a bite. Hunger level: {eater.HungerLevel} --- Remainging food: {Dish.Bites}");
                    eater.IsEating = false;
                }
            }
            Monitor.Pulse(Locker);

        }
Beispiel #6
0
 protected virtual void OnTakeBiteEvent(Philosopher eater, TakeBitEventArgs e)
 {
     TakeBiteEvent?.Invoke(eater, e);
 }