Golang

Go routines

Very light-weight user-level threads

  • 100KiB go routines vs. 2MiB OS thread
  • stack starts small and grows as needed
  • Context Switch is a function call rather than a system call

Go channels

Example

func worker(done chan bool) {
  // Notify the main routine
  done <- true
}

func main() {
  // Create a channel to notify us
  done := make(chan bool, 1)
  // Create go routine
  go worker(done)
  // Block until we receive a message
  next() // <- start executing here when worker is done done
}