Go Concurrency : Introduction
This is what I got from Learning Go : Chapter 12 book :
Concurrency
- Concurrency : breaking up a single process into independent components and specifying ho these components safely share data.
- Go's concurrency model is based on Communicating Sequential Processes (CSP).
- Use concurrency when we want to combine data from multiple operations that can operate independently.
- Concurrency operations are often used for I/O.
Process & Thread
- A process : an instance of a program that is being run by a computer's operating system.
- A process is composed of one or more threads.
- A thread : an unit of execution that is given some time to run by the operating system.
- Threads within a process share access to resources.
Goroutine
- Goroutine is a lightweight thread, managed by the Go runtime.
- Goroutine creation is faster than thread creation, bcs we aren't creating an operating system-level resource.
- Goroutine initial stack sizes are smaller than thread stack sizes and can grow as needed -> that's why goroutine is more memory efficient.