📝 Process Synchronization in Solaris (36 MCQs)
Solaris Kernel Synchronization and Locking Architecture
Solaris provides synchronization mechanisms for coordinating kernel threads and protecting shared operating system data structures. Its traditional kernel synchronization facilities include adaptive mutexes, condition variables, readers-writer locks, and semaphores. These mechanisms support different resource-access patterns and execution contexts, allowing the kernel to protect shared state while balancing processor utilisation, blocking overhead, and multiprocessor concurrency.
Why Solaris Uses Multiple Locking Strategies
Kernel operations vary in duration and execution context. Some critical sections are extremely short and benefit from spinning, while longer operations should allow waiting threads to sleep. Read-heavy structures also require efficient simultaneous access. Solaris uses different synchronization mechanisms to avoid unnecessary blocking, protect shared resources, and support scalable execution across multiple processors.
Adaptive Mutexes, Condition Variables, and Read-Write Locks
An adaptive mutex can spin while its owner is running on another processor, then block if the owner is not progressing. Condition variables allow threads to wait for specified events while releasing an associated lock. Readers-writer locks permit concurrent readers but require exclusive writer access, while semaphores coordinate resource counts and event ordering.
Choosing an Adaptive Mutex for a Short Critical Section
Suppose kernel thread T1 holds an adaptive mutex for a short operation on one CPU, while T2 requests the same lock on another CPU. T2 may spin briefly while T1 continues executing. If T1 stops running or the wait becomes unsuitable for spinning, T2 can block until the lock is released.
Multiprocessor Efficiency and Priority-Aware Synchronization
Solaris synchronization mechanisms support concurrent kernel execution, memory management, and resource coordination. Adaptive behaviour can avoid unnecessary sleeping when lock owners are actively progressing. However, spinning wastes CPU time if critical sections remain occupied too long. Priority-related blocking, lock ordering, and synchronization overhead must also be managed to preserve system responsiveness.
Misconceptions About Solaris Locking Mechanisms
'An adaptive mutex always makes waiting threads sleep' is incorrect because it may spin while the owner runs. 'Readers-writer locks permit concurrent writers' is incorrect because writers require exclusive access. 'Spinning is always more efficient than blocking' is incorrect because prolonged contention wastes processor capacity.
Exam Focus: Adaptive Mutex and Read-Write Lock Behaviour
Explain how an adaptive mutex chooses between spinning and blocking, and compare it with a conventional sleeping mutex. Trace reader and writer access under a readers-writer lock. Questions may examine condition variables, semaphore operations, multiprocessor contention, and why synchronization primitives must match the duration and context of protected operations.
Key Terms of Solaris Synchronization
- Adaptive mutex - Lock combining spinning and blocking.
- Condition variable - Coordinates event-based waiting.
- Readers-writer lock - Allows shared reads and exclusive writes.
- Semaphore - Synchronization through resource permits.
- Spin - Repeatedly checks a lock condition.
- Lock contention - Competition for protected access.
📝 All Process Synchronization in Solaris MCQs
Q1. A Solaris service runs four kernel threads that each add one to a shared counter 500 times. The final value is 1,842. Which explanation best accounts for the shortfall from 2,000?
📖 Explanation: An increment usually reads, changes, and writes the counter. Two threads can read the same old value and then overwrite one another's results. Protecting the complete update with a mutex or atomic operation prevents these lost increments.
Q2. Two Solaris processes map the same shared-memory queue, but each initializes a separate process-private mutex in its own address space. Why can both still modify the queue simultaneously?
📖 Explanation: Mutual exclusion works only when all participants coordinate through the same underlying object. Separately allocated process-private mutexes remain independent, even when they guard the same shared data. Interprocess coordination requires shared storage and compatible process-sharing setup.
Q3. In a Solaris kernel, when is brief spinning on an adaptive mutex most likely to be useful?
📖 Explanation: Brief spinning can avoid sleep and wake-up overhead when the lock owner is actively running and likely to release the mutex soon. If the owner is not progressing, continued spinning wastes processor time and blocking is preferable.
Q4. A kernel developer estimates that spinning costs 100 CPU cycles per microsecond. Suspending and waking a waiter costs about 700 cycles. For an expected wait of 12 microseconds, which choice has the lower estimated cost?
📖 Explanation: The estimated spin cost is cycles. Blocking costs about 700 cycles, so it is cheaper under these assumptions. A shorter expected wait could reverse the comparison, depending on actual scheduling and lock-release timing.
Q5. A Solaris data structure is searched by many threads and modified only occasionally. Which access pattern best justifies considering a reader-writer lock?
📖 Explanation: A reader-writer lock allows compatible read operations to overlap while excluding readers and other writers during modification. It is most useful when reads are frequent, writes are relatively rare, and the protected work justifies the added lock-management cost.
Q6. Readers R1 and R2 both hold a shared read lock when writer W requests exclusive access. What must be true before W can enter its protected write section?
📖 Explanation: A writer requires exclusive access, so it cannot enter while existing readers hold the shared lock. The readers must leave first. Whether new readers may join ahead of the writer depends on the lock's documented fairness policy.
Q7. A Solaris consumer waits for a producer to place an item in a shared queue. Which condition-variable design correctly coordinates the consumer?
📖 Explanation: The queue predicate records whether work actually exists; a condition variable only notifies a waiter that the state may have changed. The consumer checks the predicate while holding the mutex and repeats the check after each wake-up.
Q8. A consumer checks that a queue is empty while holding mutex M, unlocks M, and only afterward registers on condition variable C. A producer inserts an item and signals C in between. What flaw is present?
📖 Explanation: The separate unlock and wait-registration steps create a lost-wakeup window. A producer can change the predicate and signal before the consumer becomes a waiter. The condition wait must atomically release the mutex while blocking, followed by predicate rechecking.
Q9. A Solaris producer signals a condition variable while no consumer is waiting. A consumer begins waiting later. What should the consumer rely on to determine whether work exists?
📖 Explanation: Condition-variable notifications are not generally accumulated like semaphore permits. A signal issued with no waiter may have no lasting effect. The durable information must be represented by shared state, checked under the associated mutex before waiting and after waking.
Q10. A Solaris semaphore represents six available identical devices. Four successful wait operations occur, followed by two successful post operations, with no other activity. What is the resulting permit count?
📖 Explanation: Each successful wait consumes one permit and each post adds one. Starting from six, the count becomes . The result represents four available devices, assuming no operation failed or was interrupted.
Q11. A Solaris worker successfully waits on a semaphore for a device, then terminates before posting the permit. Other workers later remain blocked. Which explanation best fits the behavior?
📖 Explanation: A semaphore records permits, not necessarily which thread owns each one. If a worker exits after consuming a permit without returning it, the count can stay reduced. An application needs cleanup or recovery logic for such failure paths.
Q12. A semaphore starts at 8. Three tasks each perform one successful wait but mistakenly perform two posts before finishing. Assuming no maximum-count failure or other activity, what is the final count?
📖 Explanation: Each task consumes one permit and returns two, producing a net increase of one. Across three tasks, the count changes by , so the final value is .
Q13. A Solaris application protects a counter and related status field with mutex M. One code path updates the counter using an atomic instruction without acquiring M. Why can the overall invariant still fail?
📖 Explanation: An atomic instruction protects its individual read-modify-write operation, not the relationship between the counter and status field. Mixing it with a separate mutex protocol can expose intermediate combinations. All conflicting paths must follow a compatible synchronization design.
Q14. A service uses one mutex for thousands of unrelated cache records. Profiling shows long waits but very short individual updates. Which redesign is most directly worth evaluating?
📖 Explanation: A single mutex serializes independent record updates and can become a scalability bottleneck. Partitioning the state can allow unrelated operations to proceed concurrently. Operations spanning partitions still need a consistent locking protocol to preserve invariants and avoid deadlock.
Q15. Two Solaris threads may need mutexes A and B. One path acquires A before B, while another acquires B before A. Which policy most directly prevents this circular-wait pattern?
📖 Explanation: A consistent global acquisition order prevents threads from forming the opposing dependency cycle in which each holds one mutex and waits for the other. It addresses this deadlock pattern, although contention and starvation may still require separate attention.
Q16. A thread acquires a Solaris mutex, but a different thread later attempts to release that mutex. What should the reviewer generally conclude about this design?
📖 Explanation: A mutex normally represents ownership as well as exclusion. Releasing it from a non-owner is not a valid general protocol and may be rejected or produce undefined behavior, depending on the primitive. The acquiring thread should perform the matching release.
Q17. Thread T1 updates two fields while holding mutex M, then unlocks M. Thread T2 later locks the same M before reading both fields. Which guarantee is central to this sequence?
📖 Explanation: The mutex provides mutual exclusion and a synchronization relationship between release and a later successful acquisition. When all conflicting accesses use the same protocol, T2 can observe T1's completed protected updates rather than an unsynchronized intermediate state.
Q18. A Solaris program protects writes to a configuration field with mutex M, but a reader accesses that field without M because reads are usually harmless. The writer occasionally changes it. What is the concern?
📖 Explanation: A read-only operation can still conflict with a concurrent write. Since the reader bypasses the synchronization protocol, it may observe an inconsistent value or create a data race. Immutable publication, atomic access, or consistent locking is required.
Q19. A Solaris service publishes a new immutable configuration snapshot and immediately frees the old snapshot. Some readers may still hold pointers to the old version. What essential step is missing?
📖 Explanation: Publishing a replacement does not prove that readers have stopped using the previous version. Reclamation must wait for a safe point, such as a grace period or equivalent lifetime protocol, or readers may dereference freed memory.
Q20. A producer-consumer queue stores both its items and a separate count. Which practice best prevents the count from drifting away from the actual queue contents?
📖 Explanation: The queue and count describe related state and must change consistently. Protecting both under one suitable protocol prevents consumers from relying on stale information and maintains the invariant that the count matches the number of available items.
Q21. A Solaris thread repeatedly polls a shared flag in a tight loop while waiting for another thread to finish. CPU usage remains high, but no useful work is performed. What is happening?
📖 Explanation: A tight polling loop repeatedly consumes CPU time while waiting for a state change. For longer waits, a condition variable, semaphore, or other blocking mechanism can suspend the waiter and let the processor execute useful work.
Q22. A thread repeatedly requests a resource and is bypassed by other threads each time it becomes available. Those other threads continue completing work. Which problem does this describe?
📖 Explanation: Starvation occurs when a particular thread is continually denied access despite overall system activity. Unlike deadlock, other threads can keep progressing. Fair allocation, bounded waiting, or a revised acquisition policy may be needed to prevent it.
Q23. Two Solaris kernel threads access a linked list. One inserts a node while the other traverses the list, and neither uses synchronization. What is the most serious risk?
📖 Explanation: Insertion changes multiple pointer relationships, so an unsynchronized traversal can observe an intermediate structure or follow an invalid pointer. Correct protection must coordinate structural changes, traversal, and memory reclamation rather than merely protect the new node.
Q24. A kernel service holds mutex M while updating a record and writing a diagnostic message to a slow device. Several unrelated threads then wait on M. What redesign best preserves correctness while reducing avoidable blocking?
📖 Explanation: Slow output extends the lock hold time and can create additional lock-order dependencies. When correctness permits, capture the information needed for logging while protected, release the mutex, and perform the potentially blocking output afterward.
Q25. A Solaris service records throughput as thread count increases. Data: (1,120 requests/s); (2,220); (4,390); (8,610); (16,625); (32,620). Which interpretation best fits the trend?
📖 Explanation: Throughput rises as concurrency increases, then changes very little beyond eight threads. This pattern suggests that lock contention, serialized work, memory bandwidth, or another shared resource is limiting additional parallelism rather than thread count alone.
Q26. A monitor records this trace: time 0, waiters 1 and completions 12; time 1, waiters 3 and completions 12; time 2, waiters 5 and completions 12; time 3, waiters 7 and completions 12; time 4, waiters 9 and completions 12. What is the strongest diagnosis?
📖 Explanation: A rising waiter count with no additional completions indicates stalled progress while demand continues. The trace alone does not prove a specific deadlock, but it warrants checking held locks, dependency cycles, ownership, and missing cleanup or release paths.
Q27. A benchmark varies the fraction of operations that are writes: (0%,1000 ops/s); (10%,970); (20%,910); (40%,780); (60%,620); (80%,430). What does the pattern suggest about a reader-writer lock?
📖 Explanation: As the write fraction rises, more operations require exclusive access and fewer can benefit from concurrent reading. A reader-writer lock is most attractive for read-heavy workloads; frequent writes can reduce its concurrency advantage and add bookkeeping overhead.
Q28. A measurement gives spin costs of 100 cycles per microsecond: (1 us,100 cycles); (2,200); (4,400); (8,800); (16,1600). If blocking costs about 800 cycles, at what wait duration do the estimates become equal?
📖 Explanation: The estimated spin cost equals the blocking cost when , giving microseconds. Below that estimate, spinning may cost less; above it, blocking may be cheaper, subject to real scheduling and wake-up variation.
Q29. A Solaris application divides work into repeated phases. Every worker must finish the current phase before any worker begins the next. Which synchronization primitive most directly represents this requirement?
📖 Explanation: A barrier provides a rendezvous point for a defined group of participants. Threads wait until the required arrivals occur, then continue to the next phase. It coordinates phase completion but does not automatically protect unrelated shared data.
Q30. A producer can add four jobs before any consumer begins waiting. The system must ensure that all four jobs remain discoverable. Why is a condition variable signal alone insufficient as the job count?
📖 Explanation: A condition variable is a notification mechanism, not a stored count of pending events. The queue itself must record the four jobs and be checked under its mutex, or a counting semaphore can represent the available job permits.
Q31. A Solaris driver manages several identical devices and also maintains a linked list describing each device's owner. Which design best separates the two synchronization responsibilities?
📖 Explanation: The counting semaphore represents how many devices are available, while the mutex protects compound updates to the ownership list. They serve different purposes and can be combined, provided acquisition order and failure cleanup preserve the resource accounting.
Q32. Kernel thread T1 holds a short-lived adaptive mutex and is currently running on another CPU. Thread T2 requests the same mutex. Which response is most consistent with the adaptive strategy described in Solaris synchronization?
📖 Explanation: An adaptive mutex can use a short spin when its owner is executing on another processor and may release the lock soon. If the owner is not running or the wait persists, blocking avoids wasting CPU cycles.
Q33. Thread T1 successfully waits on a Solaris semaphore representing a pending event. Thread T2 later posts the semaphore when the event occurs. Which statement best distinguishes this from ordinary mutex ownership?
📖 Explanation: A semaphore coordinates through a count of permits or events rather than exclusive ownership by one thread. A different thread can post to make a permit available, whereas a mutex normally follows an owner-based acquire and release protocol.
Q34. A shared table is read thousands of times per second, updated once per minute, and each read performs substantial work. Which choice is most likely to benefit from a reader-writer lock?
📖 Explanation: Frequent, substantial read operations can overlap under a reader-writer lock, while occasional writes obtain exclusive access. The read-heavy workload can justify the extra bookkeeping; very short or write-heavy operations may gain little from this primitive.
Q35. A code review finds that function F locks mutex M before changing a shared record, but function G changes the same record without locking M. The developer claims the record is protected because F uses a mutex. What is the correction?
📖 Explanation: A mutex protects data only when conflicting code paths use the same synchronization protocol. Function G can still race with F because it bypasses the lock. All readers and writers must coordinate, or the data needs another safe design.
Q36. A cache reader acquires read lock R and then requests metadata mutex M. A cache writer acquires M first and then requests R exclusively. Under contention, what single policy change most directly removes this lock-order cycle?
📖 Explanation: Reader holds R awaiting M; writer holds M awaiting exclusive R, forming a cycle. Enforce R-before-M ordering on all paths so neither can hold the later lock while waiting for the earlier lock.