To Understand Process Synchronization

Procedure

A. For Dining Philosopher's Problem:

  1. Start Simulation:
    • Click on the START button.
    • All philosophers will be in the "Thinking" state.
    • All chopsticks will be available.
    • The State Table will show the initial state.
    • The State Arrays (Philosopher's State and Chopstick State) will be displayed.
    • The Code (written in pseudo code) will appear for reference.
  2. Interact with Philosophers:
    • Pick Left Chopstick: Click on a philosopher's circle. The philosopher will attempt to pick up the chopstick on their left and change it's state to taken and philosopher's state to hungry.
    • Pick Right Chopstick: Click on the philosopher again. They will now attempt to pick up the chopstick on their right and change it's state to taken.
    • Start Eating: Click on the philosopher once more.The philosopher's state will change to "Eating".
    • Stop Eating: Click on the philosopher one last time. They will release both chopsticks and return to the "Thinking" state.
  3. Deadlock:
    A deadlock can occur if all philosophers pick up their left chopsticks simultaneously. In this situation, no philosopher can acquire the right chopstick needed to eat, and the system becomes stuck.
    If you encounter a deadlock, click on the RESET button to restart the simulation.
  4. Observe and Analyze:
    State Table: The State Table shows the current state of each philosopher (Thinking, Eating, Hungry) and the availability of the chopsticks (Available, Busy, Taken).
    State Arrays: The State Arrays provide a more concise representation of the states:
    • Philosopher's State: A list indicating whether each philosopher is thinking or eating.
    • Chopstick State: A list indicating whether each chopstick is available or taken.
    Code: The code (written in pseudo code) is highlighted to show the corresponding actions being performed.

B.For Producer-Consumer Problem:

  1. Click the START button to initialize the value of local (in & out) and shared (n, empty, full & S) variables.
  2. Now, click on either 'Producer' or 'Consumer' to initiate their respective code.
  3. To execute the 'Producer/Consumer' code line by line, click their respective 'Next Line' button.
  4. Repeat step 3 until the code for the initiated process is completed.
  5. After each click, observe the comment section and changes in variables.

Try different simulation scenarios such as:

  • Consuming the product before producing it.
  • Producing/consuming more than one item simultaneously.
  • Explore context switching scenarios by not executing all lines of code and instead, clicking on either 'Producer' or 'Consumer'.

NOTE 1: The algorithm used to resume a process from the waiting list is 'First-in, First-out'.

NOTE 2: To understand the instructions in the code, hover over the line.

NOTE 3: Read all the alerts carefully.