Understanding Go Routines
Published: 7/10/2025
Understanding Go Routines
Go routines are a lightweight thread of execution. They are not OS threads, but rather functions that run concurrently with other functions or methods.
Key Characteristics:
- Lightweight: Go routines are very cheap to create, with initial stack sizes typically a few kilobytes.
- Multiplexed: Go’s runtime multiplexes Go routines onto a smaller number of OS threads.
- Communicating Sequential Processes (CSP): Go encourages communication by sharing memory, not sharing memory by communicating. This is done through channels.
Example:
package main
import (
"fmt"
"time"
)
func sayHello() {
fmt.Println("Hello from a goroutine!")
}
func main() {
go sayHello()
fmt.Println("Hello from main!")
time.Sleep(1 * time.Second) // Give the goroutine time to execute
}This simple example demonstrates how to launch a Go routine using the go keyword. The main function will continue its execution concurrently with sayHello.
goconcurrencygoroutines
← Back to Blog