Cpu

burn cpu use golang

December 9, 2021
Go
Cpu

虚假的 burn # package main func fakeBurn() { for { } } 真正的 burn # package main import ( "flag" "fmt" "runtime" "time" ) var ( numBurn int updateInterval int ) func cpuBurn() { for { for i := 0; i < 2147483647; i++ { } // Gosched yields the processor, allowing other goroutines to run. It does not suspend the current goroutine, so execution resumes automatically. // Gosched让当前goroutine让出处理器,从而使得其它goroutine可以运行。它不会挂起/暂停当前的goroutine,它会自动恢复执行。 runtime. ...