开始:同时调用方法对我不起作用[重复]

This question already has an answer here:

I'm new to Go. I'm trying out this example where I want to perform a concurrent call from a method. This isn't working for me (I don't see the output).

Based on "Effective Go", it says concurrency is supported for methods and functions. What am I doing wrong?

Thanks, -Srikanth

package main

import (
    "fmt"
)

type Hello struct {
    a int
}

func (h *Hello) Myprint (value string) {
    go func() {
        fmt.Println(value)
    } ()
}

func main() {
    h := &Hello{100}

    go h.Myprint("need to go")
}
</div>

Your main exits and the process dies before the goroutine has a chance to print the output.