/**
兩人同時打印,競爭資源
輸出:
F:\goWorkSpace\study\05協程>go run 08_解決多任務資源競爭問題.go
wheolrlldo
並不是helloword,爲了解決此問題;後續我們來學習chanel
*/
package main
import (
"fmt"
"time"
)
func Printer(str string){
for _,data:=range str{
fmt.Printf("%c",data)
time.Sleep(time.Second)
}
}
func person1(){
Printer("hello")
}
func person2(){
Printer("world")
}
func main(){
//新建兩個協程,代表兩個人去打印,2個人同時使用打印機
go person1()
go person2()
for{}
}