Goroutines are lightweight threads built into the language. You simply have to put the word go in front of a function call to have the function execute in a thread. Goroutines may also be referred to as threads in this book.
Go does provide mutexes, but they are avoidable in most cases and will not be covered in this book. You can read more about mutexes in the sync package documentation at https://golang.org/pkg/sync/. Channels should be used instead for sharing data and communicating between threads. Channels were covered earlier in this chapter.
Note that the log package is safe to use concurrently, but the fmt package is not. Here is a short example of using goroutines:
package main
import (
"log"
"time"
)
func countDown() {
for i := 5; i >= 0; i-- {
log.Println(i)
time.Sleep(time.Millisecond * 500)
}
}
func main() {
// Kick...