Problem Statement
What are common concurrency pitfalls in Swift and how can you mitigate them (for example deadlocks, race conditions, priority inversion)?
Explanation
Concurrency in Swift (as in other languages) introduces pitfalls such as race conditions when multiple threads access shared state without synchronization; deadlocks when tasks wait on each other; priority inversion where a high-priority task is blocked by a lower-priority one; and thread explosion or resource exhaustion when too many concurrent tasks are spawned. /n/n To mitigate these you should use safe concurrency constructs: `actor` types to isolate state, `DispatchQueue` with proper QoS and priority management, `Task` and structured concurrency for async/await, avoid shared mutable state or protect it via locks or barriers, prefer immutable data where possible, and profile using Instruments and the Thread Sanitizer. Recognizing and discussing these in an interview shows you are prepared for real-world Swift development.