You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am not sure if this behaviour is expected, but I could not find any documentation regarding it.
According to the documentation:
LoadOrStore returns the existing value for the key if present.
Otherwise, it stores and returns the given value.
The loaded result is true if the value was loaded, false if stored.
I naturally expect that if the value is returned by a function, that function is not invoked if the key already exists.
What version of Go are you using (go version)?
go1.10.3
Does this issue reproduce with the latest release?
N/A
What operating system and processor architecture are you using (go env)?
Darwin / amd64
What did you do?
I tried to store a value into the sync.Map concurrently, by using LoadOrStore method, with the same key.
This doesn't have anything to do with sync.Map; you're incrementing functionCallCounter before LoadOrStore is even called. This version has the same semantics; maybe that makes it clearer what's happening: https://play.golang.org/p/x31ExkgLzIO
I am not sure if this behaviour is expected, but I could not find any documentation regarding it.
According to the documentation:
I naturally expect that if the value is returned by a function, that function is not invoked if the key already exists.
What version of Go are you using (
go version
)?go1.10.3
Does this issue reproduce with the latest release?
N/A
What operating system and processor architecture are you using (
go env
)?Darwin / amd64
What did you do?
I tried to store a value into the
sync.Map
concurrently, by usingLoadOrStore
method, with the same key.https://play.golang.org/p/PQ3pye-SZGN
What did you expect to see?
I expected to see that the function
Foo
was only invoked once by thesMap.LoadOrStore
method.What did you see instead?
The
sMap.LoadOrStore
method did only store once, but it invoked theFoo
function 10 times.The text was updated successfully, but these errors were encountered: