Go 为什么不调用atomic.Load在runtime.GC中加载gcphase?

Go 为什么不调用atomic.Load在runtime.GC中加载gcphase?,go,runtime,Go,Runtime,我想知道为什么gcphase不受atomic.Load的保护: n := atomic.Load(&work.cycles) if gcphase == _GCmark { // Wait until sweep termination, mark, and mark // termination of cycle N complete. gp.schedlink = work.sweepWaiters.head work.sweepWaiters.hea

我想知道为什么
gcphase
不受
atomic.Load的保护:

n := atomic.Load(&work.cycles)
if gcphase == _GCmark {
    // Wait until sweep termination, mark, and mark
    // termination of cycle N complete.
    gp.schedlink = work.sweepWaiters.head
    work.sweepWaiters.head.set(gp)
    goparkunlock(&work.sweepWaiters.lock, "wait for GC cycle", traceEvGoBlock, 1)
} else {
    // We're in sweep N already.
    unlock(&work.sweepWaiters.lock)
}
有人知道吗?

代码摘录:

func setGCPhase(x uint32) {
    atomic.Store(&gcphase, x)
    writeBarrier.needed = gcphase == _GCmark || gcphase == _GCmarktermination
    writeBarrier.enabled = writeBarrier.needed || writeBarrier.cgo
}
虽然
gcphase
是一个全局变量,但对
gcphase
的所有写入都是通过上述函数完成的

运行时中有几个变量没有正确配对,但似乎它们有理由这样做,并且确信它们拥有对它的独占访问权

这里是关于同样的问题,GC开发人员在这里讨论了改变同样的问题