1 min readAug 19, 2020
Goroutines in Go
If you have learned the operating system, you should be very familiar with the thread and process. Generally speaking, the thread is a lightweight one compared with the process. However, we find an even lightweight one in Go which is Goroutine. In this article, I’d like to summarize what I have learned about the Goroutines in Go.
Advantages of Goroutines[1]
- Goroutines are cheaper than threads.
- Goroutine is stored in the stack and the size of the stack can grow and shrink according to the requirement of the program. But in threads, the size of the stack is fixed.
- Goroutines can communicate using the channel and these channels are specially designed to prevent race conditions when accessing shared memory using Goroutines.
- Suppose a program has one thread, and that thread has many Goroutines associated with it. If any of Goroutine blocks the thread due to resource requirement then all the remaining Goroutines will assign to a newly created OS thread. All these details are hidden from the programmers.
Reference
[1] https://www.geeksforgeeks.org/goroutines-concurrency-in-golang/