小编Yal*_*ang的帖子

在sync.Once 的上下文中,“热路径”是什么意思?

go version:1.13.4 在源码中sync/once.go,下面的注释提到了“热点路径”:

type Once struct {
    // done indicates whether the action has been performed.
    // It is first in the struct because it is used in the hot path.
    // The hot path is inlined at every call site.
    // Placing done first allows more compact instructions on some architectures (amd64/x86),
    // and fewer instructions (to calculate offset) on other architectures.
    done uint32
    m    Mutex
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:

  1. 这里的“热路径”是什么意思?

  2. “它是结构中的第一个”是否使“热路径”访问更有效?为什么?

go

17
推荐指数
1
解决办法
1483
查看次数

golang 中是否存在可见性问题?

例如,如果我在一个 goroutine 中更新一个全局变量,然后在另一个 goroutine 中读取该变量,我可以获得最新的值吗?

另一个问题是,“atomic.Load*”和“atomic.Store*”能否确保可见性?

go

-4
推荐指数
1
解决办法
98
查看次数

标签 统计

go ×2