1kasa commented on PR #2862:
URL: https://github.com/apache/dubbo-go/pull/2862#issuecomment-2858036091
It's like this. For example, multiple goroutines access a shared cache (such
as proto.registries) at the same time, and these goroutines need to obtain the
registry object based on the same cacheKey. If we use Load and Store, when
multiple goroutines access it at the same time, it may happen that the `if
!loaded {}` condition is executed, resulting in two identical Registry objects
being stored in the cache, causing duplicate creation. After using LoadOrStore
(which itself guarantees concurrent safety), no matter how many goroutines
access it at the same time, as long as one goroutine successfully creates and
stores the registry object, other goroutines will directly load the object from
the cache, and duplicate creation will not occur.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]