OpenAI

Verified interview challenge

ModalLock and FairModalLock

Build two thread locks that let compatible work run together and keep waiting groups moving.

Unlock with Full Access

The 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.

Your coding workspacePreview
Current partFurther parts unlock as you progress
solution.pyPython 3.13
class ModalLock:
    ...

class FairModalLock:
    ...
Current-part checks

Run your code to see results.

The complete sequence, starter code and checks are included with Full Access.