Exemple #1
0
        static void Main(string[] args)
        {
            Fork fork = new Fork();

            new Philosopher(1, 10, 50, fork);
            new Philosopher(2, 20, 40, fork);
            new Philosopher(3, 30, 30, fork);
            new Philosopher(4, 40, 20, fork);
            new Philosopher(5, 50, 10, fork);
        }
Exemple #2
0
 public Philosopher(int PhiloNumber, int ThinkDelay, int EatDelay, Fork fork)
 {
     this.PhiloNumber = PhiloNumber;
     this.ThinkDelay  = ThinkDelay;
     this.EatDelay    = EatDelay;
     this.fork        = fork;
     LeftFork         = PhiloNumber == 0 ? 4 : PhiloNumber - 1;
     RightFork        = (PhiloNumber + 1) % 5;
     new Thread(new ThreadStart(Run)).Start();
 }