博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使go协程按顺序输出结果
阅读量:3993 次
发布时间:2019-05-24

本文共 276 字,大约阅读时间需要 1 分钟。

借助一个切片来完成

s := make([]chan int, 0)for i := 0; i < 10; i++ {
t := make(chan int) s = append(s, t) n := i go func() {
t <- n }()}rand.Seed(time.Now().UnixNano())for _, v := range s {
k := 1+rand.Int63n(6) time.Sleep(time.Duration(k) * time.Second) fmt.Println(<-v)}

转载地址:http://ujaui.baihongyu.com/

你可能感兴趣的文章
杂七杂八的
查看>>
linux spi
查看>>
linux spi dev test program
查看>>
Overview of Linux kernel SPI support
查看>>
i.mx53 uboot
查看>>
linux 驱动开发 头文件
查看>>
嵌入式linux 开发板 dhcp ip
查看>>
/etc/resolv.conf
查看>>
/etc/hosts
查看>>
container_of()传入结构体中的成员,返回该结构体的首地址
查看>>
linux sfdisk partition
查看>>
ipconfig,ifconfig,iwconfig
查看>>
opensuse12.2 PL2303 minicom
查看>>
电平触发方式和边沿触发的区别
查看>>
中断函数中不能调用ioremap()!!!!!!!
查看>>
网络视频服务器移植
查看>>
Encoding Schemes
查看>>
EFM32TG222F32连接JLink V8问题
查看>>
Keil问题
查看>>
移植QT
查看>>