文章分类 -  go

摘要:1、基于信号的抢占式调度 1.1 main 函数 可以看到在main goroutine起来后,就启动了sysmon 线程 src/runtime/proc.go:146 func main() { mp := getg().m ..... mainStarted = true if GOARCH 阅读全文
posted @ 2024-06-20 22:54 G1733 阅读(32) 评论(0) 推荐(0) 编辑
摘要:retake函数 在分析调度器初始化的时候我们说过,sysmon系统监控线程会定期(10毫秒)通过retake函数对goroutine发起抢占,下面我们直接从retake函数开始。 runtime/proc.go : 4376 // forcePreemptNS is the time slice 阅读全文
posted @ 2024-06-19 00:22 G1733 阅读(8) 评论(0) 推荐(0) 编辑
摘要:1 准备工作 1.1 创建一个main.go package main import "fmt" type ss struct { a_b string b int64 } func x(c chan int) { b :{"", 4} if b.a_b != "" { return } c<-23 阅读全文
posted @ 2024-06-18 19:34 G1733 阅读(6) 评论(0) 推荐(0) 编辑
摘要:1、创建新的M 1.1 从 sched.freem 中获取一个空闲的m,或者new 一个m // Create a new m. It will start off with a call to fn, or else the scheduler. // fn needs to be static 阅读全文
posted @ 2024-06-17 23:49 G1733 阅读(18) 评论(0) 推荐(0) 编辑
摘要:1、入口 1.1 准备go程序 package main func test() int { return 1 } func main() { go test() } 编译 go build main.go 1.2 使用readelf 查找入口 root@xxx:/data# readelf -h 阅读全文
posted @ 2024-06-17 14:56 G1733 阅读(8) 评论(0) 推荐(0) 编辑
摘要:1、创建main goroutine schedinit完成调度系统初始化后,返回到rt0_go函数中开始调用newproc() 创建一个新的goroutine用于执行mainPC所对应的runtime·main函数,看下面的代码: runtime/asm_amd64.s : 197 # creat 阅读全文
posted @ 2024-06-13 00:05 G1733 阅读(15) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示