Short Trick Of Process Synchronization ( Solve any question in few minutes).

Short Trick Of Process Synchronization ( Solve any question in few minutes).



play-rounded-fill play-rounded-outline play-sharp-fill play-sharp-outline
pause-sharp-outline pause-sharp-fill pause-rounded-outline pause-rounded-fill
00:00

Here’s a short trick guide to help you quickly solve any Process Synchronization question in GATE (or similar competitive exams) in a few minutes:


Contents [hide]

🧠 Topic: Process Synchronization

🎯 Goal: Identify Mutual Exclusion, Progress, Bounded Waiting in code
🧪 Target: GATE-level MCQs or code analysis


✅ TRICK 1: Look for the 3 Magic Words

Always check if the algorithm/code satisfies:

  1. Mutual Exclusion – Only 1 process in the Critical Section

  2. Progress – No unnecessary blocking

  3. Bounded Waiting – Every process eventually gets a turn

📝 Tip: If even one of these is violated, it’s not a correct solution.


✅ TRICK 2: Remember the CORE ALGORITHMS

Algo No. Name Processes Hardware Needed Reliable? Notes
1 Simple Lock 2+ No ❌ Violates progress
2 Dekker’s Algo 2 No ✅ Software-only
3 Peterson’s Algo 2 No ✅ Easy to simulate
4 Test-and-Set Lock 2+ Yes (Atomic op) ✅ Uses hardware instruction
5 Semaphore 2+ No ✅ wait() and signal()
6 Monitor 2+ No ✅ High-level abstraction

🔑 Peterson’s = Most Common in GATE Questions!


✅ TRICK 3: Identify the Entry & Exit Sections

Quickly scan the code for these patterns:

🟩 Entry Section (wants to enter CS):

  • flag[i] = true; → intention to enter

  • turn = 1 - i; → gives other process a chance

  • while(...) → busy wait / condition checking

🟥 Exit Section (leaves CS):

  • flag[i] = false;

  • turn = ...; → resets turn for the other process


✅ TRICK 4: Use This YES/NO Table

Condition to Check Look for in Code Shortcut Decision
Mutual Exclusion? Only one process allowed in CS ✅ if while(flag[] && turn) pattern exists
Progress? No unnecessary delay if CS is free ✅ if turn changes appropriately
Bounded Waiting? Process won’t wait forever ✅ if turn is assigned fairly

✅ TRICK 5: Look for Common MCQ Keywords

Watch for these question patterns:

  • “Which condition is violated?”
    → Use the YES/NO table above

  • “How many processes can be in CS?”
    → If more than one, Mutual Exclusion is violated

  • “What is the purpose of turn or flag[]?”
    flag[] = intent, turn = fairness

  • “Identify correct algorithm from options”
    → Match pattern to Peterson, Dekker, etc.


✅ Super Short Summary

🔓 flag[] = true → process wants to enter
🛑 while (flag[other] && turn == other) → wait
✅ Critical Section
🔁 Reset flag[i] = false, set turn = other


⚡ Example (Peterson’s):

c
flag[i] = true;
turn = 1 - i;
while (flag[1 - i] && turn == 1 - i)
; // wait

// Critical Section

flag[i] = false;

📌 This ensures:
✔ Mutual Exclusion
✔ Progress
✔ Bounded Waiting


Would you like:

  • A printable cheat sheet?

  • Practice MCQs with answers?

  • Visual flowcharts for each algorithm?

Let me know!

Short Trick Of Process Synchronization ( Solve any question in few minutes).

Process Synchronization Race Condition: Critical Section …

Chapter 5: Process Synchronization



Leave a Reply

Your email address will not be published. Required fields are marked *

error: