5.8 van a resolver el problema de la competencia por los recursos multitarea

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

 

Publicados 134 artículos originales · alabanza won 104 · Vistas a 50000 +

Supongo que te gusta

Origin blog.csdn.net/h4241778/article/details/105374224
Recomendado
Clasificación