Short Trick Of Process Synchronization ( Solve any question in few minutes).
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
- 1 Topic: Process Synchronization
- 1.1 TRICK 1: Look for the 3 Magic Words
- 1.2 TRICK 2: Remember the CORE ALGORITHMS
- 1.3 TRICK 3: Identify the Entry & Exit Sections
- 1.4 TRICK 4: Use This YES/NO Table
- 1.5 TRICK 5: Look for Common MCQ Keywords
- 1.6 Super Short Summary
- 1.7 Example (Petersonβs):
- 1.8 Short Trick Of Process Synchronization ( Solve any question in few minutes).
- 1.9 Process Synchronization Race Condition: Critical Section β¦
- 1.10 Chapter 5: Process Synchronization
Topic: Process Synchronization
TRICK 1: Look for the 3 Magic Words
Always check if the algorithm/code satisfies:
-
Mutual Exclusion β Only 1 process in the Critical Section
-
Progress β No unnecessary blocking
-
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 | while(flag[] && turn) pattern exists |
| Progress? | No unnecessary delay if CS is free | turn changes appropriately |
| Bounded Waiting? | Process wonβt wait forever | 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
turnorflag[]?β
βflag[]= intent,turn= fairness -
βIdentify correct algorithm from optionsβ
β Match pattern to Peterson, Dekker, etc.
Super Short Summary
flag[] = trueβ process wants to enterwhile (flag[other] && turn == other)β waitCritical Section Reset flag[i] = false, setturn = other
Example (Petersonβs):
Would you like:
-
A printable cheat sheet?
-
Practice MCQs with answers?
-
Visual flowcharts for each algorithm?
Let me know!