Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Write flag is turned on when deleting a key from a map, even if the key doesn't exist #40327
What version of Go are you using (
Why would you want to do this in the first place, though? At best, it makes no sense. At worst, it's considered a data race, which is why the runtime panics.
Concurrently reading and attempting to write or delete a key from a map is a data race. The data race detection during normal runtime is best effort and might not trigger for all data races.
The runtime race detection is a tradeoff between simplicity, performance and race detection. There are cases e.g. for uninitialised maps were the map runtime race detection might not trigger however if run with race instrumentation those cases might still be detected as data races.
If the goroutine attempting deletion is known always to not delete a key to goroutine does not need to try to delete the key. If the goroutine sometimes actually deletes a key then this will trigger a data race warning even if the map implementation is changed to not set the hashWriting flag when no actual internal structure is changed.
In the current implementation there might not be a write to internal data structures but in the future there might be e.g. for bookkeeping and internal reorgantzaiion of the map for shrinking (even if no key was found).