Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Race Safety on Atomicity leaves me with a doubt #124

Open
bjo0 opened this issue Jul 16, 2024 · 2 comments
Open

Data Race Safety on Atomicity leaves me with a doubt #124

bjo0 opened this issue Jul 16, 2024 · 2 comments

Comments

@bjo0
Copy link

bjo0 commented Jul 16, 2024

https://www.swift.org/migration/documentation/swift-6-concurrency-migration-guide/dataracesafety#Atomicity

Because the current isolation domain is freed up to perform other work, actor-isolated state may change after an asynchronous call. As a consequence, you can think of explicitly marking potential suspension points as a way to indicate the end of a critical section.

func deposit(pineapples: [Pineapple], onto island: Island) async {
   var food = await island.food
   food += pineapples
   await island.store(food)
}

This code assumes, incorrectly, that the island actor’s food value will not change between asynchronous calls. Critical sections should always be structured to run synchronously.

The phrase This code assumes, incorrectly leaves me with a major doubt about what I'm supposed to be taking away from this section. What's the correct way to use suspension points as a way to indicate the end of a critical section?

@mattmassicotte
Copy link
Collaborator

Just to make sure I understand, are you saying the last sentence is unclear?

Critical sections should always be structured to run synchronously.

@bjo0
Copy link
Author

bjo0 commented Jul 18, 2024

The code block and subsequent sentence seem like a non sequitur of the prior sentences.

I was expecting to see an example of how to use explicitly marking potential suspensions points as a way to indicate the end of a critical section. I can see why the code block is problematic; but I'd like to know how to do it correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants