Monday 12 March 2012

Dining-Philosophers Problem



  • Shared data 
                                semaphore chopstick[5];
                                Initially all values are 1
  • Philosopher i: 
                                do
                                {
                                wait(chopstick[i])
                                wait(chopstick[(i+1) % 5])
                                …
                                eat
                                …
                                signal(chopstick[i]);
                                signal(chopstick[(i+1) % 5]);
                                …
                                think
                                …
                                } 
                                while (1);

No comments:

Post a Comment