5.8は、リソースの競合のマルチタスクの問題を解決するために行きます

/**
 两人同时打印,竞争资源
 输出:
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{}
	
	
	
}

 

公開された134元の記事 ウォンの賞賛104 ・は 50000 +を見て

おすすめ

転載: blog.csdn.net/h4241778/article/details/105374224