Programming/golang

golang runtime.GOMAXPROCS()

구차니 2024. 2. 15. 09:22

golang은 1개 cpu만 쓰도록 되어 있다는데

요즘 버전에서는 어떻게 바뀌었나 확인은 필요할 것 같다.

 

해보니 전체 코어 갯수 만큼 돌리도록 설정되는 듯. (go 1.20.4에서 테스트)

func GOMAXPROCS ¶
func GOMAXPROCS(n int) int
GOMAXPROCS sets the maximum number of CPUs that can be executing simultaneously and returns the previous setting. It defaults to the value of runtime.NumCPU. If n < 1, it does not change the current setting. This call will go away when the scheduler improves.

func

 

 

[링크 : https://pkg.go.dev/runtime#NumCPU]

[링크 : https://pkg.go.dev/runtime#GOMAXPROCS]

 

[링크 : https://pyrasis.com/book/GoForTheReallyImpatient/Unit33/01]