A goroutine is a lightweight thread of execution that is managed by the Go language runtime.
A goroutine is a lightweight thread of execution that is fully managed by the Go language runtime. The creators of Go felt that existing terms (e.g. threads, coroutines, processes) would incorrectly suggest exactly what a goroutine is, so they coined the new word.
The go
keyword is used to execute a function in a new goroutine:
go f(x, y)
f
, x
, and y
are evaluated in the current goroutine, and then a new goroutine is started where f
executes.
A goroutine runs in the same address space as the goroutine that started it. Goroutines may or may not be run in a different OS thread. Most often, goroutines communicate through channels.
More Information:
See Also: