Document caml_domain_alone - #13952
Merged
Merged
Conversation
Contributor
|
The change looks good to me. Incrementing |
kayceesrk
approved these changes
Apr 11, 2025
Member
Author
|
Thanks all! Merging now. |
Contributor
|
Thank you for the explanation! For future reference: there was a small mishap in that a line suppression that should have been part of the second commit ended up as part of the first commit. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While working on #13950, @OlivierNicole asked whether
caml_domain_alone ()sequential fast paths are really correct.Olivier asked: what if a new domain somehow gets spawned during the sequential fast path?
After thinking more about this, I conclude that it is in fact not possible for a new domain to start during a
caml_domain_alone()critical section.Intuitively this is guaranteed by the fact that if we hold the domain lock, and if we don't call
caml_domain_spawnourselves in the critical section, then no one else is around to call it either so no new domain can start. But in practice the reasoning is a bit delicate.Commits
In the first commit, I document this assumption and try my best to explain why I believe that it currently holds, in trunk. There is a subtlety, which is that some domain initialization code runs after the new domain gets the domain lock, but before
caml_num_domains_runningis incremented (caml_domain_alone()iscaml_num_domains_running == 1). This initialization code could contain sequential fast paths protected bycaml_domain_alone()for sequential fast paths, but this should be okay because the only other domain running is the parent domain, and the parent domain is waiting on the child domain (and listening to the void for STW requests).In the second commit, I remove the subtlety by making sure that a spawning domain increments
caml_num_domains_runningright after acquiring its own domain lock, so that the domain-initialization code never observescaml_domain_alone (). This makes the reasoning about the correctness ofcaml_domain_alone ()much simpler.cc @OlivierNicole and maybe @stedolan, @NickBarnes.