소스코드:

func maxParallelism() int 
  maxProcs := runtime.GOMAXPROCS(0)
  numCPU := runtime.NumCPU()
  if maxProcs < numCPU {
    return maxProcs
  }
  return numCPU
} 

설명:

기본으로 설정되어 있는 고루틴 개수와 CPU 개수와 비교하여 많은 걸 반환하는 함수.

만약 CPU 개수보다 더 많이 사용하고 싶다면 runtime.GOMAXPROCS 파라미터를 설정하면 된다.

'Nam Site > Go' 카테고리의 다른 글

[Go] File ReadLine (1)  (0) 2016.08.08
[Go] 변수타입 알아보기  (0) 2016.08.04

Code :

package main

import (
  "fmt"
  "reflect"
  "time"
)

func main() {
  var now time.Time = time.Now().UTC()
  fmt.Println("now is a type of: ", reflect.TypeOf(now))
  var name string = "Carl Johannes"
  fmt.Println("name is a type of: ", reflect.TypeOf(name))
  var age int = 5
  fmt.Println("age is a type of: ", reflect.TypeOf(age))
}


Output:

$ go run type_of.go
now is:  time.Time
name is:  string
age is:  int

'Nam Site > Go' 카테고리의 다른 글

[Go] 고루틴(goroutine) 개수 설정하기  (0) 2016.09.02
[Go] File ReadLine (1)  (0) 2016.08.08

+ Recent posts