sync: clarify if it's valid to call Map methods inside the Map.Range callback #46399
Labels
Documentation
Issues describing a change to documentation.
FrozenDueToAge
help wanted
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
Map is documented as safe for concurrent use, so I understand it is safe to call a method like LoadAndDelete while Range is running in another goroutine, for example.
However, what isn't clear is whether I can call a method like LoadAndDelete in Range's callback. Technically it's not a concurrent call, as it's happening on the same goroutine - it's just a nested call, as it happens within Range.
Is that supported? From my reading of the code it seems like it shouldn't cause a data race. I wonder if it could lead to undesirable effects however, such as if I delete a key that I haven't ranged over yet, or if I keep adding more keys and potentially make the range run for a long time.
I don't know what the answer is or what it should be, but I think the docs could be a bit clearer.
cc @rsc @ianlancetaylor @dvyukov @aclements as per https://dev.golang.org/owners
The text was updated successfully, but these errors were encountered: