Practice
Solution
Step 1: Identify synchronization needs
Producers must wait if the buffer is full; consumers must wait if empty. This requires tracking counts of empty and full slots.Step 2: Role of counting semaphores
Counting semaphores elegantly track available slots (empty) and filled slots (full), enabling blocking waits without busy-waiting.Step 3: Need for mutual exclusion
A mutex is required to protect concurrent access to the buffer itself to avoid race conditions.Step 4: Why other options fail
Mutex alone (A) cannot block producers/consumers based on buffer state; spinlocks (C) waste CPU cycles; condition variables (D) require mutexes and signaling to work correctly in this scenario.Final Answer:
Option C -> Option CQuick Check:
Counting semaphores + mutex is the classic producer-consumer solution [OK]
- Assuming mutex alone handles waiting
- Using spinlocks wastes CPU
- Thinking condition variables alone suffice
Solution
Step 1: Recall Round Robin preemption
When a process's time quantum expires, it is preempted to ensure fairness and allow other processes CPU access.Step 2: Understand queue management
The preempted process is placed at the end of the ready queue to wait for its next turn.Step 3: Analyze incorrect options
The process continues running until it voluntarily yields the CPU contradicts RR's preemption principle. The process is terminated and removed from the system is incorrect because process termination depends on completion, not quantum expiry. The process is moved to the waiting queue for I/O is incorrect unless the process requests I/O, which is unrelated to quantum expiration.Final Answer:
Option A -> Option AQuick Check:
Quantum expiry -> preempt -> enqueue at ready queue's end.
- Thinking process runs until completion ignoring quantum
- Confusing preemption with process termination
- Assuming process moves to waiting queue without I/O
Solution
Step 1: Understand system call invocation
System calls are invoked by user programs to request kernel services. This requires a mode switch from user to kernel mode.Step 2: Role of CPU hardware
The CPU provides a mechanism (trap or software interrupt) that safely switches the mode and transfers control to the OS kernel.Step 3: Why other options are incorrect
The user-level application itself triggers the mode switch directly is wrong because user applications cannot directly change CPU mode for protection reasons. The operating system scheduler decides when to switch modes is incorrect because the scheduler manages process execution but does not trigger mode switches on system calls. The device driver initiates the mode switch is wrong because device drivers run in kernel mode and do not initiate mode switches from user mode.Final Answer:
Option B -> Option BQuick Check:
System call -> trap -> CPU switches mode -> kernel handles request [OK]
- Thinking user code can directly switch CPU mode
- Confusing scheduler role with mode switching
- Believing device drivers initiate user-to-kernel transitions
Solution
Step 1: Review binary semaphore properties
Binary semaphores do not enforce ownership; any thread can signal.Step 2: Review mutex properties
Mutex enforces ownership; only locking thread can unlock.Step 3: Analyze each statement
A is correct; B is correct; C is incorrect because binary semaphores lack ownership enforcement; D is correct.Final Answer:
Option C -> Option CQuick Check:
Binary semaphore ownership enforcement is the key difference from mutex.
- Assuming binary semaphore enforces ownership like mutex
- Confusing signaling with mutual exclusion
- Believing mutexes are used for signaling
Solution
Step 1: Understand aging purpose
Aging gradually increases the priority of waiting processes to ensure they eventually get CPU time, preventing starvation.Step 2: Identify downside
Over-aggressive aging can cause priority inversion, where lower-priority processes gain higher priority than intended, disrupting scheduling fairness.Step 3: Analyze options
Aging increases priority of waiting processes to prevent starvation but can cause priority inversion if overused correctly states aging's purpose and downside. Aging decreases priority of high-priority processes to prevent deadlock but may cause livelock incorrectly associates aging with deadlock prevention and livelock. Aging randomly changes priorities to balance load but can lead to starvation of critical processes misrepresents aging as random priority changes. Aging forces processes to release resources periodically but increases overhead significantly confuses aging with resource release policies.Final Answer:
Option A -> Option AQuick Check:
Aging = priority boost to prevent starvation, risk of priority inversion.
- Confusing aging with deadlock prevention
- Thinking aging randomly changes priorities
