Verified interview challenge
ModalLock and FairModalLock
Build two thread locks that let compatible work run together and keep waiting groups moving.
Unlock with Full AccessThe challenge
Implement ModalLock so threads using the same mode can run together while other modes wait. Then build FairModalLock, where waiting groups take their turn in order. You write both implementations in one Python file across five stages of a 75-minute mock.
What you'll practise
Shared access
Allow compatible callers to proceed together while other modes wait.
Fair admission
Preserve the order of incompatible requests without serialising compatible callers.
Concurrent state
Keep admission and release correct as threads wait, wake and finish in different orders.
class ModalLock:
...
class FairModalLock:
...Run your code to see results.