chenyahui / chenyahui.github.io

My blog
http://www.cyhone.com
0 stars 2 forks source link

Golang 定时器底层实现深度剖析 | 编程沉思录 #51

Open chenyahui opened 4 years ago

chenyahui commented 4 years ago

https://www.cyhone.com/articles/analysis-of-golang-timer/

本文将基于 Golang 源码对 Timer 的底层实现进行深度剖析。主要包含以下内容: Timer 和 Ticker 在 Golang 中的底层实现细节,包括数据结构等选型。 分析 time.Sleep 的实现细节,Golang 如何实现 Goroutine 的休眠。 注:本文基于 go-1.13 源码进行分析,而在 go 的 1.14 版本中,关于定时器的实现略有一些改变,以后会再专门写一

yalay commented 4 years ago

讲的不错,赞一个

icpd commented 2 years ago

1.13是会起一个timeproc 协程,1.14则不会么?

chenyahui commented 2 years ago

@whoisix 1.13是会起一个timeproc 协程,1.14则不会么?

没有对1.14之后的timer做具体研究,大致看了下,似乎是由每个P来调度timer了。这样的话,应该就不存在timeproc 这个goroutine了。不过这里不太确定,还需要细致研究下