Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Friday, Dec 4.Claim the deal

A machine-learning platform runs many short-lived jobs at the same time, each on its own thread. Every job is one of two types: a generation job ("gen") or a scoring job ("score"). The two kinds of jobs compete for the same hardware in incompatible ways, so the platform needs a coordination rule: jobs of the same type may run together, but jobs of different types must never run at the same time.

Design this coordination primitive, a lock called MutexTaskLock. Each job wraps its work between a call to acquire and a call to release: it calls acquire before it starts and must be blocked there until it is safe to run, and it calls release once it has finished. The lock must be thread-safe, since many threads call acquire and release concurrently, and it must not busy-wait while a job is blocked.

Stdout
-