+/EE360P
distributed systems
git clone https://git.julia.blue/+/EE360P
df69975
master
1class DiningPhilosopher implements Resource { 2int n =0 ; 3BinarySemaphore []fork =null ; 4public DiningPhilosopher (int initN ) { 5n =initN ; 6fork =new BinarySemaphore [n ]; 7for (int i =0 ;i <n ;i ++) { 8fork [i ] =new BinarySemaphore (true ); 9 } 10 } 11public void acquire (int i ) { 12fork [i ].P (); 13fork [(i +1 ) %n ].P (); 14 } 15public void release (int i ) { 16fork [i ].V (); 17fork [(i +1 ) %n ].V (); 18 } 19public static void main (String []args ) { 20DiningPhilosopher dp =new DiningPhilosopher (5 ); 21for (int i =0 ;i <5 ;i ++) 22new Philosopher (i ,dp ); 23 } 24}