Sobes.tech
Junior

Kes juhib goroutine-sid Go keeles?

sobes.tech AI

Vastus AI-lt

Goroutines in the Go language are managed by the built-in scheduler of the Go runtime. This scheduler is responsible for distributing goroutines across system threads (OS threads) and ensuring concurrent execution.

Main points:

  • The Go scheduler operates at the user level, not at the kernel level.
  • It efficiently switches between goroutines, allowing thousands of lightweight tasks to run.
  • The developer simply starts a goroutine with go and does not manage threads directly.

Example of starting a goroutine:

func sayHello() {
    fmt.Println("Hello from goroutine")
}

func main() {
    go sayHello() // the scheduler will start this goroutine
    time.Sleep(time.Second) // to give time for the goroutine to execute
}