We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please answer these questions before submitting your issue. Thanks!
go version
1.13.6 我在阅读您的blog 《深入golang-runtime的调度》看到 main goroutine启动的时候是在m0中启动,然后在执行proc.go main函数中有一个newm(sysmon, nil) 好像是新建一个m线程去执行sysmon监控,也就是说sysmon是不是独立一个线程运行? 但是我在测试调度的时候发现,如果gorouine里面做了一个无限循环,在用户main函数循环内创建多个goroutine(超过runtime.GOMAXPROCS个)发现在最终调用的时候就只要runtime.GOMAXPROCS个被执行,另外其他的goroutine并没有被执行,如果按照源代码中以及您的分析,应该会被sysmon进行抢占,把P和m剥离再创建新的m线程去执行其他的goroutine,但是从结果来看,好像sysmon并不是独立线程而是和某个m共用了,导致m如果被占用就无法做出抢占和调度,不知道是否是这个原因?代码如下:
package main import ( "fmt" "sync" ) var wg sync.WaitGroup func process(id int) { fmt.Printf("id: %d\n", id) for { // time.Sleep(time.Second) } // wg.Done() } func main() { runtime.GOMAXPROCS(4) // println(runtime.NumCPU()) wg.Add(1) for i := 0; i < 10; i++ { go process(i) } wg.Wait() }
最终输出的只要 4个
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.13.6
我在阅读您的blog 《深入golang-runtime的调度》看到
main goroutine启动的时候是在m0中启动,然后在执行proc.go main函数中有一个newm(sysmon, nil) 好像是新建一个m线程去执行sysmon监控,也就是说sysmon是不是独立一个线程运行?
但是我在测试调度的时候发现,如果gorouine里面做了一个无限循环,在用户main函数循环内创建多个goroutine(超过runtime.GOMAXPROCS个)发现在最终调用的时候就只要runtime.GOMAXPROCS个被执行,另外其他的goroutine并没有被执行,如果按照源代码中以及您的分析,应该会被sysmon进行抢占,把P和m剥离再创建新的m线程去执行其他的goroutine,但是从结果来看,好像sysmon并不是独立线程而是和某个m共用了,导致m如果被占用就无法做出抢占和调度,不知道是否是这个原因?代码如下:
最终输出的只要 4个
The text was updated successfully, but these errors were encountered: