Exemple #1
0
        private void Eat()
        {
            firstFork.PickUp(this);
            secondFork.PickUp(this);

            State = PhilospherState.EATING;
            Thread.Sleep(50);
            Bites++;

            firstFork.PutDown(this);
            secondFork.PutDown(this);
        }
Exemple #2
0
        private void Eat()
        {
            tableSemaphore.Wait();

            lock (firstFork)
            {
                lock (secondFork)
                {
                    tableSemaphore.Release();

                    firstFork.PickUp(this);
                    secondFork.PickUp(this);

                    State = PhilospherState.EATING;
                    //   Thread.Sleep(50);
                    Bites++;

                    firstFork.PutDown(this);
                    secondFork.PutDown(this);
                }
            }
        }