golang-design / under-the-hood

📚 Go: Under The Hood | Go 语言原本 | https://golang.design/under-the-hood

Home Page:https://golang.design/under-the-hood

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ch08GC/termination: 写屏障状态描述不准确

hw676018683 opened this issue · comments

实际描述

标记终止 | 保证一个周期内标记任务完成,停止写屏障 | STW | 关闭

预期描述

标记终止 | 保证一个周期内标记任务完成,停止写屏障 | STW | 开启

标记终止阶段是 STW 的,写屏障已经关闭,原文无错误。

https://github.com/changkun/go-under-the-hood/blob/master/book/zh-cn/part2runtime/ch08GC/cycle.md

func setGCPhase(x uint32) {
	atomic.Store(&gcphase, x) // *gcphase = x
	// 只有 mark 和 marktermination 才需要写屏障
	writeBarrier.needed = gcphase == _GCmark || gcphase == _GCmarktermination
	// 只有需要或者 cgo 时候才启用写屏障
	writeBarrier.enabled = writeBarrier.needed || writeBarrier.cgo
}

但后面写的,又说没关闭啊

可以以这么说,但是不准确。实际实现上写屏障并不是整个阶段开启的,我优化一下描述