文章目录
多线程打印
package main
import (
"runtime"
"fmt"
)
func main(){
go sayHello()
go sayWorld()
var str string
fmt.Scan(&str)
}
func sayHello(){
for i := 0; i < 10; i++{
fmt.Print("hello\n")
runtime.Gosched()
}
}
func sayWorld(){
for i := 0; i < 10; i++ {
fmt.Print("world\n")
runtime.Gosched()
}
}
输出结果
world
hello
world
hello
hello
hello
hello
hello
hello
hello
hello
hello
world
world
world
world
world
world
world
world
参考链接:
- https://www.cnblogs.com/zitjubiz/p/15375046.html