Skip to content

Instantly share code, notes, and snippets.

@PoplarYang
Last active May 7, 2020 15:47
Show Gist options
  • Select an option

  • Save PoplarYang/e7f5b9717b6f83a600f833192aaac048 to your computer and use it in GitHub Desktop.

Select an option

Save PoplarYang/e7f5b9717b6f83a600f833192aaac048 to your computer and use it in GitHub Desktop.
goroutine和channel
package main
import (
"fmt"
"runtime"
"time"
)
func main() {
var array [10]int
runtime.GOMAXPROCS(2) // 限制使用CPU的数量
fmt.Println("Running in", runtime.Version()) // version
for i := 0; i < 10; i++ {
go func(i int) {
for {
array[i]++
}
}(i)
}
time.Sleep(time.Second)
fmt.Println(array)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment