Build a Countdown Latch to Gate Parallel Build Steps

Last updated: November 29, 2026

Quick Overview

A build orchestrator starts several compile tasks in parallel and must wait until all of them finish before linking. Implement a reusable-style countdown latch with count_down and wait (with optional timeout) using a lock and condition variable.

Microsoft
Software Engineering Fundamentals
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Medium

0

0

0 solved


A build orchestrator starts several compile tasks in parallel and must wait until all of them finish before linking. Implement a reusable-style countdown latch with count_down and wait (with optional timeout) using a lock and condition variable.

Concurrency primitives are a frequent Microsoft onsite topic, especially for teams on build systems, Windows, and Azure infrastructure. The interviewer wants correct use of a condition variable (waiting in a loop on a predicate, notify_all), timeout handling, and an understanding of how a latch differs from a barrier or semaphore.

What the Interviewer Expects
  • Uses a condition variable with a predicate loop to avoid spurious wakeups
  • Wakes all waiters when the count reaches zero
  • Handles timeouts and returns a clear result
  • Ignores extra count_down calls safely
  • Explains latch versus barrier versus semaphore
Key Topics to Cover
condition variables
synchronization primitives
spurious wakeups
timeouts
parallel builds
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you make this a cyclic barrier that resets for the next phase?
  • What happens if a compile task crashes and never counts down?
  • How would you implement this without a lock using atomics?
  • How does this map to CountdownEvent in .NET?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • CountDownLatch(n): starts at n.
  • count_down(): decrements, never below zero; when it hits zero, releases every waiter.
  • wait(timeout=None): blocks until zero; returns True if released, `...
High-Level Design

Protect the counter with a Condition. Waiters sleep on the condition and re-check the predicate count == 0 every time they wake, because condition variables allow spurious wakeups and another ...


Submit Your Answer
Markdown supported