marsevilspirit commented on PR #2862:
URL: https://github.com/apache/dubbo-go/pull/2862#issuecomment-2858393567
> 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.是这样的,比如多个
goroutine 同时访问一个共享缓存(比如 proto.registries),这些 goroutine 需要根据同一个 cacheKey 获取
registry 对象。如果我们使用 Load 和 Store,当多个 goroutine 同时访问时,
可能会发生 `if !loaded {}` 条件执行,导致两个相同的 Registry 对象被存储在缓存中,造成重复创建。而使用 LoadOrStore
之后(它本身就保证了并发安全),无论有多少个 goroutine 同时访问,只要有一个 goroutine 成功创建并存储了 registry 对象,其他
goroutine 就会直接从缓存中加载该对象,不会发生重复创建。
Oh, I discovered a fatal problem. The config is a package we are about to
discard. We should implement this effect globally.
--
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]