Recall & Review
beginner
What is a data race in concurrent programming?
A data race happens when two or more tasks access the same data at the same time, and at least one task is writing to it, causing unpredictable results.
Click to reveal answer
beginner
How do actors in Swift help prevent data races?
Actors isolate their data and only allow one task to access their internal state at a time, ensuring safe access and preventing data races.
Click to reveal answer
beginner
Why is isolating state important in preventing data races?
Isolating state means only one task can change or read the data at a time, so tasks don’t interfere with each other and cause errors.
Click to reveal answer
intermediate
What happens if multiple tasks try to access an actor's data simultaneously?
Swift queues the tasks and runs them one by one, so only one task accesses the actor’s data at a time, avoiding conflicts.
Click to reveal answer
intermediate
Can you access an actor’s internal data directly from outside the actor?
No, you must use asynchronous calls to interact with an actor’s data, which helps control access and prevent data races.
Click to reveal answer
What does an actor in Swift do to prevent data races?
✗ Incorrect
Actors serialize access to their data, so only one task can access it at a time, preventing data races.
What is a data race?
✗ Incorrect
A data race occurs when multiple tasks access the same data at the same time and at least one is writing.
How do you interact with an actor’s data from outside?
✗ Incorrect
Actors require asynchronous calls to safely access their data from outside.
What happens if two tasks try to access an actor’s data at the same time?
✗ Incorrect
Swift queues tasks so only one accesses the actor’s data at a time, making others wait.
Why is state isolation important in actors?
✗ Incorrect
Isolating state ensures tasks don’t interfere, preventing data races and errors.
Explain in your own words how actors prevent data races in Swift.
Think about how actors control who can touch their data and when.
You got /4 concepts.
Describe what a data race is and why it is a problem in concurrent programming.
Imagine two people trying to write on the same paper at the same time.
You got /4 concepts.