Recall & Review
beginner
What is the main purpose of using actors in Swift?
Actors in Swift are used to protect mutable state by ensuring that only one task accesses the actor's data at a time, preventing data races in concurrent code.
Click to reveal answer
intermediate
How do locks differ from actors in managing concurrency?
Locks provide manual control to protect shared resources by blocking threads, while actors automatically serialize access to their state without explicit locking code.
Click to reveal answer
intermediate
When should you prefer actors over locks in Swift?
Prefer actors when you want safer, easier-to-read concurrency code that avoids manual lock management and reduces risks of deadlocks and race conditions.
Click to reveal answer
intermediate
What is a potential downside of using locks instead of actors?
Locks can cause deadlocks if not used carefully and require more complex code to manage, increasing the chance of bugs in concurrent programs.
Click to reveal answer
advanced
Can actors and locks be used together in Swift? Why or why not?
Yes, actors and locks can be combined when you need fine-grained control inside an actor or to protect resources outside actor boundaries, but this adds complexity.
Click to reveal answer
What does an actor guarantee in Swift concurrency?
✗ Incorrect
Actors guarantee exclusive access to their mutable state by serializing access, preventing data races.
Which of the following is a risk when using locks manually?
✗ Incorrect
Manual locks can cause deadlocks if threads wait indefinitely for each other.
When is it better to use locks instead of actors?
✗ Incorrect
Locks provide fine-grained control, useful in some low-level or performance-critical scenarios.
Actors in Swift help prevent which common concurrency problem?
✗ Incorrect
Actors prevent data races by serializing access to their state.
What is a benefit of using actors over locks?
✗ Incorrect
Actors simplify concurrency by managing access automatically, reducing bugs.
Explain the key differences between actors and locks in Swift concurrency.
Think about how each manages access to shared data.
You got /4 concepts.
Describe scenarios when you would choose actors over locks and vice versa.
Consider safety versus control trade-offs.
You got /4 concepts.