Home/Tutorials/Go (Golang)/Goroutines and Concurrency

0 of 3 saved

Go (Golang)5 min read

Goroutines and Concurrency

Read this chapter, write the program on this page, then pass a short check to open the next one.

Run work concurrently with go.

Goroutines and Concurrency

Prefix a function call with go to run it as a goroutine. main must stay alive long enough to see the result (e.g. a short sleep in demos).

  • go worker() schedules worker concurrently.
  • Channels coordinate goroutines in real apps.
  • Demo sleeps are for learning โ€” production uses sync or channels.
package main

import (
    "fmt"
    "time"
)

func worker() {
    fmt.Println("Worker active!")
}

func main() {
    go worker()
    time.Sleep(50 * time.Millisecond)
}

After you read this chapter, use Write (when available) and Quiz on this page to lock it in โ€” same flow as C, Python, and the other Learn languages.