```go
package main
import(
"fmt"
"time"
)
//class Thread
type Thread struct{
name string
}
func (this *Thread)run()string{
fmt.Println(this.name, "start")
return ""
}
//class Threads
type Threads struct{
t map[string]Thread
}
func (this *Threads)runn()string{
for key, v:=range this.t{
fmt.Println("Key:",key, "Value:", v.name)
go v.run() //这个地方输出的不是我预期的, why
}
return ""
}
func main(){
fmt.Println("main start")
var tt Threads = Threads{}
tt.t = make(map[string]Thread)
tt.t["one"] = Thread{name:"one1"}
tt.t["two"] = Thread{name:"two2"}
tt.t["three"] = Thread{name:"three3"}
tt.runn() //why
time.Sleep(5*1e9)
fmt.Println("main end")
}
```
有疑问加站长微信联系(非本文作者)