请教go routine,为什么总是先打印大写字母

lxp926 · 2018-04-11 10:12:01 · 969 次点击 · 大约8小时之前 开始浏览    置顶
这是一个创建于 2018-04-11 10:12:01 的主题,其中的信息可能已经有所发展或是发生改变。

package main

import ( "fmt" "runtime" "sync" )

func main() {

// Allocate 1 logical processor for the scheduler to use.
runtime.GOMAXPROCS(1)

// wg is used to wait for the program to finish.
// Add a count of two, one for each goroutine.
var wg sync.WaitGroup
wg.Add(2)

fmt.Println("Start Goroutines")

// Declare an anonymous function and create a goroutine.
go func() {
    // Schedule the call to Done to tell main we are done.
    defer wg.Done()

    // Display the alphabet three times
    for count := 0; count < 3; count++ {
        for char := 'a'; char < 'a'+26; char++ {
            fmt.Printf("%c ", char)
        }
    }
}()

// Declare an anonymous function and create a goroutine.
go func() {
    // Schedule the call to Done to tell main we are done.
    defer wg.Done()

    // Display the alphabet three times
    for count := 0; count < 3; count++ {
        for char := 'A'; char < 'A'+26; char++ {
            fmt.Printf("%c ", char)
        }
    }
}()

// Wait for the goroutines to finish.
fmt.Println("Waiting To Finish")
wg.Wait()

fmt.Println("\nTerminating Program")

}

Start Goroutines

Waiting To Finish

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z A B C D E F G H I J K L M N OP Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c de f g h i j k l m n o p q r s t u v w x y z

Terminating Program

请教,为什么总是大写字母先打印?我觉得应该小写字母先打印啊。


有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

969 次点击  
加入收藏 微博
2 回复  |  直到 2018-04-12 11:52:33
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传