5.8 go to solve the problem of resource competition multitasking

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

 

Published 134 original articles · won praise 104 · views 50000 +

Guess you like

Origin blog.csdn.net/h4241778/article/details/105374224