← Questions

Implement a mutex without built-in locks

0
AppleCodingLast asked Aug 2026

Build a lock with lock() and unlock() without using any lock, mutex, semaphore, monitor or condition variable the language or a library provides. Build it from atomic operations such as compare-and-swap (or a classic algorithm like Peterson's for two threads). Then answer fundamentals questions: what your lock relies on from the hardware and memory model, why spinning wastes CPU and how to back off or park threads, fairness, and what happens if a thread unlocks a lock it does not hold.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding