course/Concurrency/gomaxprocs.go

32 lines
370 B
Go
Raw Normal View History

2024-07-07 20:52:43 +08:00
package main
import (
"fmt"
"runtime"
"sync"
)
var wgGroup sync.WaitGroup
func main() {
runtime.GOMAXPROCS(2) //指定P的数量
wgGroup.Add(2)
go a()
go b()
wgGroup.Wait()
}
func a() {
defer wgGroup.Done()
for i := 0; i < 10; i++ {
fmt.Printf("A:%v\n", i)
}
}
func b() {
defer wgGroup.Done()
for i := 0; i < 10; i++ {
fmt.Printf("B:%v\n", i)
}
}