DevPrep

All topics › Swift Concurrency (async/await, actors)

What is actor reentrancy and why is it dangerous?

Senior PRO

The essence

An actor is reentrant: when one of its methods reaches an await and suspends, the actor is not blocked — it can start executing another call (including the same method from another task). When the first call resumes, the actor's state may no longer be what it saw before the await. A data race is still impossible (only one task runs inside the actor at a time), but invariants break: double loading, double charging, a stale cache. That is a race condition without a data race.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store