1 22 23 package DiningPhilosophers; 24 25 public class DiningPhilosophers { 26 27 public static final int NUM_PHILS = 2; 29 30 public static void main(String args[]) { 31 32 Fork[] forks = new Fork[NUM_PHILS]; 34 for (int i=0; i<NUM_PHILS; i++) { 35 System.out.println("Creating fork#: "+i); 36 forks[i]=new Fork(i); 37 } 38 39 Philosopher[] philosophers = new Philosopher[NUM_PHILS]; 41 for (int i=0; i<NUM_PHILS; i++) { 42 System.out.println("Creating philosopher#: "+i); 43 philosophers[i]=new Philosopher(i, forks[i], forks[(i+1)%NUM_PHILS]); 44 philosophers[i].start(); 45 } 46 } 47 } 48 | Popular Tags |