本文摘自php中文网,作者藏色散人,侵删。
下面由golang教程栏目给大家详解Golang cpu的使用设置,希望对需要的朋友有所帮助!以下测试,使用的Go版本是1.8.3
不设置
如果没有调用runtime.GOMAXPROCS 去设置CPU,Golang默认使用所有的cpu核。
测试机器CPU有4个核,测试代码开启4个goroutine,从测试结果看4个核心全部跑满。
测试代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
设置CPU使用
1 |
|
GOMAXPROCS sets the maximum number of CPUs that can be executing simultaneously and returns the previous setting. If n < 1, it does not change the current setting.
设置并发执行时使用的CPU的数目
相关阅读 >>
a simple txt file processing tool by golang
更多相关阅读请进入《golang》频道 >>
Go语言101
一个与时俱进的Go编程知识库。