Deadlock-Free Solution to Dining Philosophers Problem Using Semaphores
Deadlock-Free Solution to Dining Philosophers Problem Using Semaphores 1. Aim To implement a deadlock-free solution for the Dining Philosophers Problem using semaphores . 2. Objective To study process synchronization To avoid deadlock and race conditions To ensure mutual exclusion using semaphores 3. Problem Statement Five philosophers sit around a circular table. Each philosopher alternates between thinking and eating . To eat, a philosopher must acquire both left and right chopsticks . The challenge is to design a solution that: Avoids deadlock Avoids race condition Allows maximum parallelism 4. Theory Why Deadlock Occurs (Naive Solution) If all philosophers pick up their left chopstick first , a circular wait occurs → deadlock . Deadlock-Free Strategy Used We use a binary semaphore room that allows only 4 philosophers to try picking chopsticks at the same time. This breaks circular wait , one of the four deadlock conditions. 5...