Sobes.tech
Junior — Middle

Where are new goroutines created in a Go program?

sobes.tech AI

Answer from AI

New goroutines in Go are created using the keyword go, followed by a call to a function or method. This occurs at the point in the program where the go statement is written. For example:

func main() {
    go doSomething() // a new goroutine is created here
    // the main goroutine continues execution
}

func doSomething() {
    // code executed in the new goroutine
}

Thus, creating a goroutine is an explicit call with go at any point in the code where you want to run a function concurrently.