Cab Ride Allocator: a Concurrency Barrier Problem (the Uber ride question)
The Uber ride concurrency interview question: seat ride-request threads into cabs of four — 4+0, 0+4, or 2+2 only — with a mutex, two semaphores, and a barrier. Deadlock-free, stress-tested.
The conference just let out. A few hundred people spill onto the curb, phones up, all tapping the same ride app at once. Each person belongs to one of two political parties, and the cabs seat four. To keep the peace, a cab may leave with four of one party, or two-and-two — never anything else. Get it wrong and the ride turns into a brawl. That is the whole problem, and it is a deceptively deep one — it was the opening question for a Principal Engineer round at Arcesium. It is not really about cabs. It is the barrier problem in disguise: a thread must block until enough compatible threads have …
What’s inside
Read this one free
Sign in and your first premium article is on us — read Cab Ride Allocator: a Concurrency Barrier Problem (the Uber ride question) free.