Reserve shared inventory without overbooking

Serialize a check-and-mutate operation and explain why protecting only the write is not enough.

SwiftConcurrencyGCD

Practice

concurrentPerform simulates many clients trying to reserve the last tickets at the same time. The mid-level interview bug is not just "use a queue somewhere"; it is making the check and mutation one atomic operation.

Protect the inventory so exactly 100 reservations succeed and no tickets remain. After your code passes, explain why moving only remaining -= 1 onto the queue would still be wrong.

swift 5.2

Edit the starter code, then Run to compile it and check your answer. Runs Swift 5.2 on the server (Linux); UIKit, SwiftUI, and long-running async are not supported.