Practice
Solution
Step 1: Identify what is saved during thread context switch
Only the CPU registers and stack pointer specific to the thread are saved and restored, since threads share the process memory space.Step 2: Understand process state remains unchanged
The process's memory and resources remain intact; no need to save or reload the entire process state.Step 3: Evaluate options
The OS saves the entire process state and reloads it for the new thread incorrectly saves the entire process state. The OS flushes the process's memory cache and reloads it for the new thread incorrectly flushes memory cache. The OS terminates the current thread and creates a new thread for the next task incorrectly terminates and recreates threads.Final Answer:
Option D -> Option DQuick Check:
Thread context switch saves/restores thread-specific CPU state only [OK]
- Confusing process context switch with thread context switch
- Assuming memory cache must be flushed on thread switch
- Believing threads are terminated and recreated on each switch
Solution
Step 1: Understand semaphore roles
'empty' counts available buffer slots; 'full' counts filled slots; mutex protects buffer access.Step 2: Producer must wait for empty slot
Producer waits (P operation) on 'empty' to ensure space is available before producing.Step 3: Acquire mutex before modifying buffer
Mutex wait ensures exclusive access to buffer.Step 4: Add item, then release mutex
After adding, signal (V operation) mutex to release critical section.Step 5: Signal 'full' to indicate new item
Signaling 'full' wakes consumers waiting for items.Step 6: Why other options fail
Wait on 'full' semaphore, wait on mutex, add item, signal mutex, signal 'empty' semaphore waits on 'full' which is incorrect; Wait on mutex, wait on 'empty' semaphore, add item, signal 'full' semaphore, signal mutex waits on mutex before 'empty' which can cause deadlock; Signal 'empty' semaphore, wait on mutex, add item, signal 'full' semaphore, wait on 'full' semaphore signals before waiting, breaking synchronization.Final Answer:
Option A -> Option AQuick Check:
Wait empty -> wait mutex -> produce -> signal mutex -> signal full [OK]
- Confusing 'full' and 'empty' semaphore roles
- Incorrect order of mutex and semaphore waits
- Signaling before waiting causing race
Solution
Step 1: Role of semaphores
Semaphores can block threads and track resource counts but do not inherently provide mutual exclusion.Step 2: Need for mutual exclusion
Without a mutex, multiple producers or consumers can simultaneously modify the buffer, causing race conditions and data corruption.Step 3: Why other options are incorrect
Semaphores cannot block threads, so busy-waiting occurs is false because semaphores do block; Semaphores cause deadlocks if used without mutexes is incorrect as deadlocks depend on usage, not absence of mutex; Semaphores increase memory usage exponentially without mutex is false as semaphores do not cause exponential memory growth.Final Answer:
Option D -> Option DQuick Check:
Semaphores synchronize counts but mutex needed for exclusive buffer access [OK]
- Assuming semaphores alone prevent race conditions
- Confusing blocking behavior of semaphores
- Believing mutexes cause deadlocks by default
Solution
Step 1: Understand inode fixed size
Inodes have a fixed size that includes space for direct and indirect pointers, regardless of file size.Step 2: Analyze impact on small files
Including triple indirect pointers increases inode size, which can waste space when storing many small files.Step 3: Clarify access speed for small files
Accessing small files uses direct pointers only; indirect pointers are not traversed, so no speed penalty.Step 4: Confirm allocation behavior
Indirect blocks are allocated only when needed; small files do not allocate them.Final Answer:
Option A -> Option AQuick Check:
Fixed inode size with many pointers wastes space for small files [OK]
- Assuming indirect pointers slow down small file access
- Believing indirect blocks are allocated for small files
- Thinking triple indirect pointers have no impact on inode size
Solution
Step 1: Identify cross-machine synchronization needs
Local mutexes cannot synchronize across machines.Step 2: Evaluate distributed synchronization primitives
Distributed lock services provide mutual exclusion across processes/machines.Step 3: Binary semaphore vs counting semaphore
Binary semaphore (or mutex) semantics needed for mutual exclusion; counting semaphore allows multiple concurrent accesses, unsuitable if exclusive access required.Step 4: Spinlocks impractical across network due to busy-wait and latency
Final Answer:
Option A -> Option AQuick Check:
Distributed binary semaphore or lock service enforces mutual exclusion across machines.
- Assuming local mutexes work across machines
- Choosing counting semaphore for exclusive access
- Using spinlocks in distributed environment
