企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
### 多资源竞争 ~~~ //打印机属于公共资源 func printer(str string) { for _, data := range str { fmt.Printf("%c\n", data) time.Sleep(time.Second) } } func person1() { printer("hello") } func person2() { printer("world") } func main() { //新建两个协程,代表两个人,2个人同事使用打印机 go person1() go person2() //不让主协程结束 for { } } ~~~ 每次打印结果都不相同: ~~~ w h e o r l l l o d ~~~