π Process Synchronization in Solaris (51 MCQs)
π From Operating System β’ 5. Process Synchronization β’ 51 questions available
What is Process Synchronization in Solaris?
Definition:
Solaris process synchronization includes adaptive mutexes, reader-writer locks, and turnstiles that dynamically switch between spinning and sleeping based on lock holder state and CPU availability.
Example:
An adaptive mutex spins briefly if the owner is running on another CPU, then sleeps via turnstile if the owner is preempted, avoiding wasted spin cycles .
Reason:
Adaptive behavior optimizes for SMP environments where short critical sections benefit from spinning but long holds require sleeping, balancing latency and throughput automatically.
π All Process Synchronization in Solaris MCQs
Q1. Which synchronization mechanism in Solaris is specifically designed to protect critical data items accessed by short code segments?
π Explanation: Adaptive mutexes are optimized for short critical sections where the lock is held for less than a few hundred instructions, minimizing overhead compared to heavier mechanisms.
Q2. On a multiprocessor system, what determines whether an adaptive mutex will spin or block when a lock is unavailable?
π Explanation: If the lock holder is running on another CPU, the waiting thread spins. If the holder is not running (sleeping), the waiting thread blocks to avoid wasting CPU cycles.
Q3. Why does an adaptive mutex always cause a thread to sleep rather than spin on a single-processor system?
π Explanation: On a single-processor system, if a thread is testing a lock, the thread holding the lock cannot be running simultaneously. Therefore, spinning is futile, and sleeping is the only efficient option.
Q4. What is the primary efficiency advantage of reader-writer locks over semaphores for data that is frequently read?
π Explanation: Semaphores serialize all access, allowing only one thread at a time. Reader-writer locks permit multiple readers to access data simultaneously, improving throughput for read-heavy workloads.
Q5. Why are reader-writer locks typically reserved for longer sections of code in Solaris?
π Explanation: The implementation complexity and overhead of reader-writer locks make them inefficient for short operations. They are justified only when the critical section is long enough to benefit from concurrent read access.
Q6. What is a turnstile in the context of Solaris synchronization?
π Explanation: A turnstile is a software queue structure that manages threads waiting to acquire a specific lock, such as an adaptive mutex or reader-writer lock.
Q7. How does Solaris optimize the association of turnstiles to synchronized objects?
π Explanation: Since a thread can block on only one object at a time, associating turnstiles with threads is more efficient than assigning one to every synchronized object, reducing memory overhead.
Q8. What happens to the turnstile when the first thread blocks on a synchronized object?
π Explanation: The turnstile belonging to the first blocking thread is repurposed to serve as the queue for the synchronized object itself, optimizing resource usage.
Q9. Which protocol do Solaris turnstiles use to prevent priority inversion?
π Explanation: Turnstiles organize threads using a priority inheritance protocol, where a lower-priority lock holder temporarily inherits the priority of a higher-priority blocked thread.
Q10. What is a key difference between kernel-level and user-level locking mechanisms in Solaris regarding priority?
π Explanation: Kernel locking routines adhere to the kernelβs priority inheritance methods to prevent inversion. User-level thread-locking mechanisms do not provide this functionality, making them susceptible to inversion.
Q11. If a thread holding an adaptive mutex is currently running on another CPU, what action does the waiting thread take?
π Explanation: Spinning is chosen because the lock holder is active and likely to release the lock soon, making the wait time shorter than the cost of a context switch.
Q12. When is it more efficient to use condition variables and semaphores instead of adaptive mutexes?
π Explanation: For long code segments, the cost of spinning (wasting CPU cycles) exceeds the cost of context switching. Semaphores and condition variables allow the thread to sleep, freeing the CPU.
Q13. What triggers a waiting thread to wake up when using semaphores or condition variables in Solaris?
π Explanation: When a thread frees a lock protected by these mechanisms, it issues a signal to the next sleeping thread in the queue, waking it up to proceed.
Q14. Why is spin-waiting considered exceedingly inefficient for long code segments?
π Explanation: Spinning consumes CPU cycles without doing useful work. If the hold time is long, this waste is significant compared to the fixed cost of putting a thread to sleep and waking it later.
Q15. In Solaris, what determines if a thread will spin or sleep when encountering a locked adaptive mutex on a multiprocessor system?
π Explanation: The decision is dynamic: if the holder is running, the waiter spins; if the holder is sleeping, the waiter sleeps. This adaptivity optimizes performance based on real-time conditions.
Q16. Which of the following best describes the role of turnstiles in Solaris?
π Explanation: Turnstiles act as queues to organize and prioritize threads that are blocked while waiting for a specific lock to become available.
Q17. What happens to a lower-priority thread holding a lock when a higher-priority thread blocks on it?
π Explanation: This is the priority inheritance protocol. The lower-priority thread boosts its priority to ensure it runs sooner and releases the lock, preventing the high-priority thread from being starved.
Q18. Why does Solaris give each kernel thread its own turnstile instead of each object?
π Explanation: This design choice leverages the fact that a thread can only wait on one lock at a time, making thread-associated turnstiles more memory-efficient than object-associated ones.
Q19. Which synchronization primitive is most suitable for protecting data that is rarely modified but frequently read?
π Explanation: Reader-writer locks allow multiple concurrent readers, maximizing throughput for read-heavy scenarios, whereas mutexes and semaphores would serialize access unnecessarily.
Q20. What is the consequence of using an adaptive mutex for a very long critical section?
π Explanation: Adaptive mutexes may spin. If the section is long, spinning wastes significant CPU resources. Solaris recommends semaphores or condition variables for long sections to allow sleeping.
Q21. In a single-processor Solaris system, why is spinning never used for adaptive mutexes?
π Explanation: Since only one thread executes at a time, if a thread is checking a lock, the owner must be suspended. Spinning would just waste cycles until the scheduler switches back, so sleeping is mandatory.
Q22. What occurs when a thread releases a lock associated with a turnstile?
π Explanation: The kernel uses the turnstile queue to select the next appropriate thread (based on priority/protocol) to acquire the lock, ensuring orderly access.
Q23. Which statement accurately reflects the implementation cost of reader-writer locks in Solaris?
π Explanation: Due to their complexity in managing multiple readers and exclusive writers, reader-writer locks have higher implementation costs, limiting their use to longer critical sections.
Q24. How does Solaris handle the turnstile of the initial blocking thread after the lock is released?
π Explanation: Once the lock is released and the turnstile is no longer needed for that specific object instance, the initial threadβs turnstile is reclaimed and returned to a kernel-maintained free list.
Q25. What is the primary reason for fine-tuning locking methods in the Solaris kernel?
π Explanation: Locks are used frequently in kernel functions. Optimizing their implementation reduces overhead and contention, leading to significant overall system performance improvements.
Q26. If a thread encounters a locked adaptive mutex and the holder is sleeping, what is the waiting thread's state?
π Explanation: The waiting thread blocks (goes to sleep) because the lock holder is not running, meaning the lock will not be freed soon. Spinning would waste CPU cycles.
Q27. Which mechanism ensures that a high-priority thread is not indefinitely delayed by a low-priority thread holding a lock?
π Explanation: Priority inheritance temporarily boosts the low-priority thread's priority, allowing it to preempt other tasks and release the lock faster, thus unblocking the high-priority thread.
Q28. Why are semaphores preferred over adaptive mutexes for long critical sections?
π Explanation: Semaphores put waiting threads to sleep. For long holds, this avoids the massive CPU waste associated with spinning, making the context switch cost worthwhile.
Q29. What is the relationship between turnstiles and synchronized objects in Solaris?
π Explanation: Turnstiles are not statically bound to objects. They are associated dynamically when the first thread blocks, using that thread's turnstile as the object's queue.
Q30. Which of the following is NOT a feature of user-level thread locking in Solaris?
π Explanation: User-level locking mechanisms in Solaris do not implement priority inheritance, unlike kernel-level routines. This makes them simpler but vulnerable to priority inversion.
Q31. An adaptive mutex starts as what type of lock on a multiprocessor system?
π Explanation: Initially, it acts as a spinlock (semaphore-based). It adapts its behavior (spinning vs. sleeping) based on the state of the lock holder.
Q32. What is the threshold for considering a code segment 'short' for adaptive mutex usage?
π Explanation: Solaris defines short segments as those where the lock is held for less than a few hundred instructions, making spin-waiting acceptable.
Q33. If multiple threads are waiting on a reader-writer lock, how does the turnstile help?
π Explanation: The turnstile queues the blocked threads, allowing the kernel to select the next owner efficiently when the lock is released, respecting priority protocols.
Q34. Why is the adaptive mutex called 'adaptive'?
π Explanation: It adapts its waiting strategy: spinning if the holder is running (fast release expected) and sleeping if the holder is blocked (slow release expected).
Q35. What happens to the priority of a thread after it releases a lock acquired under priority inheritance?
π Explanation: Once the lock is released, the temporary priority boost is removed, and the thread returns to its normal, original scheduling priority.
Q36. Which scenario best justifies the use of a reader-writer lock?
π Explanation: High read frequency with rare writes is the ideal use case. Reader-writer locks allow the 100 readers to proceed concurrently, unlike mutexes which would force serial access.
Q37. In Solaris, what is the role of the 'free list' of turnstiles?
π Explanation: The kernel maintains a list of free turnstiles. When a thread needs to block and doesn't have an active turnstile association, or when one is released, this list manages availability.
Q38. Why is context switching considered 'extra cost' in synchronization?
π Explanation: Putting a thread to sleep and waking it involves saving registers, updating PCBs, and potential cache misses. This overhead is only justified if the wait time is long.
Q39. What is the behavior of an adaptive mutex on a multiprocessor system if the lock holder is pre-empted?
π Explanation: If the holder is pre-empted (not running), it is treated as a sleeping thread. The waiter sleeps to avoid spinning on a lock that won't be released until the holder is rescheduled.
Q40. Which component is responsible for selecting the next thread from a turnstile?
π Explanation: The kernel manages the turnstile queue and selects the next thread to acquire the lock based on the scheduling policy and priority inheritance rules.
Q41. What is the main disadvantage of using semaphores for very short critical sections?
π Explanation: For very short waits, the fixed cost of context switching (sleep/wake) is higher than simply spinning for a few cycles. Hence, mutexes are preferred for short sections.
Q42. How does Solaris ensure that turnstiles do not consume excessive memory?
π Explanation: Associating turnstiles with threads (which block on one object at a time) is more scalable than assigning a turnstile to every synchronized object in the system.
Q43. What is the result of priority inversion if not handled by inheritance?
π Explanation: Without inheritance, a low-priority thread holding a lock can be preempted by medium-priority threads, indefinitely blocking a high-priority thread waiting for the same lock.
Q44. Which lock type is used to protect every critical data item in Solaris by default?
π Explanation: Adaptive mutexes are the fundamental building block for protecting critical data items, especially for short accesses.
Q45. When a thread signals a condition variable, what happens to the waiting thread?
π Explanation: The signal wakes the sleeping thread, moving it to the ready queue so it can compete for the CPU and reacquire the necessary resources.
Q46. Why are reader-writer locks not used for short code segments?
π Explanation: The overhead of setting up and managing reader-writer logic is high. For short segments, a simple mutex is faster and more efficient.
Q47. What is the state of a thread in a turnstile?
π Explanation: Threads in a turnstile are blocked, waiting for a lock to be released. They are not eligible for CPU execution until they acquire the lock.
Q48. How does Solaris handle a situation where a high-priority thread blocks on a lock held by a low-priority thread?
π Explanation: Priority inheritance is used. The low-priority thread inherits the high priority, ensuring it runs quickly to release the lock.
Q49. Which of the following is true about Solaris user-level locks?
π Explanation: A crucial distinction is that user-level locking mechanisms in Solaris lack the priority inheritance protocol found in kernel routines.
Q50. What is the primary benefit of the adaptive nature of mutexes?
π Explanation: By adapting between spinning and sleeping, it minimizes CPU waste for long waits and minimizes latency for short waits, optimizing overall performance.
Q51. In Solaris, what happens if a thread tries to acquire a lock that is already held by a thread on the same CPU in a single-processor system?
π Explanation: On a single processor, the holder cannot be running if the waiter is trying to acquire. Thus, the holder must be suspended, so the waiter must sleep to yield the CPU.