Goroutines
Sample code link: (https://repl.it/@jjoco/go-routines)
Go's concurrency features are one of its main selling points over its competitors. Reading and writing concurrent programs is very easy. The "threads" in Go "go routines", and these are lightweight threads with small memory overhead. For example, a machine can run thousands of threads at a time, but that same machine can run millions of go routines. In addition, there is no need to import an extraneous package since concurrency is a core, primitive feature of the languages.
Go routines are functions that run concurrently from whichever function calls it. These are somewhat analogous to threads of other languages, though each is implemented differently under the hood.
To starting a new goroutine, use the go
keyword
1 |
|
1 2 3 4 5 6 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|