Process Synchronization - Simplified Notes
1. Multiprogramming
- Allows multiple programs to run on a single CPU by switching between them.
- Improves CPU utilization by executing another job when one is waiting for I/O.
- Has types like multitasking (runs many tasks) and multiuser (multiple users share CPU).
Sample Questions:
- What is multiprogramming?
- Differentiate between multitasking and multiuser OS.
- Why is CPU never idle in multiprogramming?
2. Process Synchronization
- Ensures that multiple processes can work together without interfering.
- Helps avoid issues like data inconsistency and deadlocks.
- Used in systems where resources are shared among processes.
Sample Questions:
- Why do we need process synchronization?
- What problems arise without proper synchronization?
- Define cooperative and independent processes.
3. Critical Section Problem
- Critical section is a code part where shared resources are accessed.
- Only one process should execute in the critical section at a time.
- Three requirements: Mutual Exclusion, Progress, and Bounded Waiting.
Sample Questions:
- What is a critical section?
- List the three conditions to solve the critical section problem.
- Explain mutual exclusion with an example.
Process Synchronization - Simplified Notes
4. Lock Variable & Test-and-Set
- Lock variable uses 0/1 to show if a resource is in use (simple but not fair).
- Test-and-Set is atomic and avoids race conditions (requires hardware support).
- Both can lead to process starvation.
Sample Questions:
- How does a lock variable work in synchronization?
- What makes Test-and-Set atomic?
- Why is bounded waiting not guaranteed in these methods?
5. Strict Alternation
- Allows only two processes to take turns in critical section.
- Uses a 'turn' variable to indicate which process can enter.
- Fails in ensuring progress if the other process is not interested.
Sample Questions:
- What is strict alternation and its drawback?
- How does the turn variable work?
- Why is strict alternation not scalable?
6. Classical IPC Problems
- Producer-Consumer: One produces data, the other consumes from shared buffer.
- Reader-Writer: Multiple readers can access data, writers need exclusive access.
- Dining Philosophers: All need two shared chopsticks to eat, can cause deadlocks.
Sample Questions:
- Explain the producer-consumer problem.
- Why is synchronization needed in reader-writer?
- What deadlock issue can arise in dining philosophers?
Process Synchronization - Simplified Notes
7. Semaphores
- Used to manage access to shared resources using wait() and signal().
- Binary semaphores (0/1) work like locks; counting semaphores allow multiple accesses.
- Used in solving classic problems like Producer-Consumer and Dining Philosophers.
Sample Questions:
- What is a semaphore and how does it work?
- Difference between binary and counting semaphore.
- Write a simple code using semaphore for critical section.