码迷,mamicode.com
首页 > 其他好文 > 详细

go 并发

时间:2019-01-27 01:14:02      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:bsp   string   pac   main   ++   nbsp   int   lis   class   

 

package main

import (
    "fmt"
    "time"
)

func say(s string) {
    for i := 0; i < 5; i++ {
        time.Sleep(100 * time.Millisecond)
        fmt.Println(s)
    }
}

func main() {
    go say("hello1")
    say("hello2")
}

输出:

hello2
hello1
hello1
hello2
hello2
hello1
hello2
hello1
hello2

 

go 并发

标签:bsp   string   pac   main   ++   nbsp   int   lis   class   

原文地址:https://www.cnblogs.com/sea-stream/p/10325398.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!