Goroutine: A Goroutine is a function or method which executes independently and simultaneously in connection with any other Goroutines present in your program. Or in other words, every concurrently executing activity in Go language is known as a Goroutines.
Thread: A process is a part of an operating system which is responsible for executing an application. Every program that executes on your system is a process and to run the code inside the application a process uses a term known as a thread. A thread is a lightweight process, or in other words, a thread is a unit which executes the code under the program. So every program has logic and a thread is responsible for executing this logic.
Here are some of the differences between Goroutine and Thread:
|Goroutines are managed by the go runtime.||Operating system threads are managed by kernal.|
|Goroutine are not hardware dependent.||Threads are hardware dependent.|
|Goroutines have easy communication medium known as channel.||Thread doesnot have easy communication medium.|
|Due to the presence of channel one goroutine can communicate with other goroutine with low latency.||Due to lack of easy communication medium inter-threads communicate takes place with high latency.|
|Goroutine doesnot have ID because go doesnot have Thread Local Storage.||Threads have their own unique ID because they have Thread Local Storage.|
|Goroutines are cheaper than threads.||The cost of threads are higher than goroutine.|
|They are cooperatively scheduled.||They are preemptively scheduled.|
|They have fasted startup time than threads.||They have slow startup time than goroutines.|
|Goroutine has growable segmented stacks.||Threads doesnot have growable segmented stacks.|