I went straight for two mutexes, one per target, which is the obvious move.
Design a solution using two semaphores (one per target) to control access, with processes acquiring the semaphore for their chosen target before calling the function. Discuss how to ensure both targets stay busy by having processes dynamically choose the less contended target, and analyze starvation and fairness implications of different selection strategies.
Pro tip: Mention that using a simple semaphore per target can lead to starvation if processes always prefer one target, so consider implementing a fair queue or a randomized selection to balance load and prevent starvation.
Identify that there are 10 processes, each needing to call a function with target A or B, and only one process per target at a time. The goal is to keep both targets busy while avoiding starvation.
Select semaphores or locks to represent each target. A binary semaphore per target ensures mutual exclusion for that target.
Each process must acquire the semaphore for its chosen target before calling the function, then release it. To keep both targets busy, processes should check availability and possibly switch targets if one is idle.
Discuss how a naive approach (e.g., always preferring A) can starve B. Propose solutions like randomized target selection, round-robin, or a fair queue to ensure both targets get utilized and no process waits indefinitely.
Compare different strategies (e.g., simple semaphores vs. fair queuing) in terms of complexity, throughput, and fairness. Highlight that fairness may reduce throughput but prevents starvation.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.