Difference between Goroutine and Thread in Golang.


Goroutine is method/function which can be executed independently along with other goroutines. Every concurrent activity in Go language is generally terms as gorountine.


Thread is a lightweight process. It can be treated as a unit to execute a piece of code. Operating system manages the thread.

Following are the important differences between Goroutine and Thread.

Sr. No.KeyGoroutineThread
1Managed ByGoroutine methods are managed by golang runtime.Thread are managed by operating systems.
2Hardware dependencyGoroutine are independent to hardware.Thread are dependent on hardware.
3Communication MediumGoroutines uses channels as communication medium.Thread have no easy communication medium.
4LatencyGoroutines can commuicate with other routines with low latency.Thread as have no communication medium, communicate with other thread with high latency.
5IDGoroutine does not have any thread local storage and no unique id.Thread have thread local storage and have unique id.
6SchedulingGoroutines are co-operatively scheduled.Threads are preemptively scheduled.
7StartupGoroutines have faster startup time.Threads have slower startup time.
8StackGoroutines have growable segmented stacks.Threads do not have growable segmented stacks.