-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
sync, x/sync/syncmap: misleading comment in map.go about entry type while p == nil #45429
Comments
At any rate, I think you are correct that it is possible for // If p == nil, the entry has been deleted, and either m.dirty == nil or
// m.dirty[key] is e. @pancl1411, does that seem more correct to you? |
CC @changkun |
I just revisited the code. The described execution flow had already existed in the old Not entirely sure why the comment was in that way but I have a theory: If that is the case, then we don't need change anything; otherwise I think the proposed comments is the right fix. What do you think? |
I think it's probably a good idea to update the comment. (It should describe invariants that are always satisfied, not just conditions that will eventually be satisfied.) |
@changkun I totally agree with your thoery, it sounds reasonable, so we don't need change anything except update comments. @bcmills the comment you update is good enough for me:
thank you all for detailed analysis and promptly apply, so should I commit this as a pull request? |
… nil As discussed in: golang#45429, about entry type comments, it is possible for p == nil when m.dirty != nil, so update the commemt about it. Fixes golang#45429
Change https://golang.org/cl/308292 mentions this issue: |
I noticed the comment in the |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
1) the misleading comment i think:
the misleading comment line about entry type while p == nil, as follows:
// If p == nil, the entry has been deleted and m.dirty == nil.
in entry type:
2) the source code logic i understand:
sync.Map
has some valid key in bothread.m
anddirty
map (which is common, and meansdirty != nil
);LoadAndDelete
to delete one of these vaild key;3) the diff between comment and code:
p == nil
withm.dirty == nil
// If p == nil, the entry has been deleted and m.dirty == nil.
p == nil
withm.dirty != nil
What did you expect to see?
code comments should cover all cases, but this one it seems not, am i misunderstand?
What did you see instead?
in code comment, If
p == nil
withm.dirty == nil
, but sometimesp == nil
withm.dirty != nil
.Additional
I am new to use golang, and not sure if I understand this correctly, so let me know if i am wrong.
thanks a lot!
The text was updated successfully, but these errors were encountered: