← Questions
Implement a mutex without built-in locks
0
I was asked this
No reports yet. Sign in to say where you were asked it.
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.
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
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
