duansen6750 2018-09-30 10:19
浏览 32

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

I wonder why gcphase is not protected with 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)
}

Anyone knows?

  • 写回答

1条回答 默认 最新

  • dtn36013 2018-09-30 12:30
    关注

    Code excerpt:

    func setGCPhase(x uint32) {
        atomic.Store(&gcphase, x)
        writeBarrier.needed = gcphase == _GCmark || gcphase == _GCmarktermination
        writeBarrier.enabled = writeBarrier.needed || writeBarrier.cgo
    }
    

    while gcphase is a global variable, but all writes to gcphase are done through the above function.

    There were several variables in runtime which aren't paired properly, but seems they have reason for it and were sure they were having the exclusive access to it.

    Here is the issue https://github.com/golang/go/issues/21931 filed about the same and here https://go-review.googlesource.com/c/go/+/65210 GC developers had some discussions on changing the same.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM