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.|
- How to pause the execution of current Goroutine?
- Difference between Thread.start() and Thread.run() in Java
- Difference between User Level thread and Kernel Level thread
- Difference between Process and Thread
- Lock framework vs Thread synchronization in Java
- Zero value in Golang
- Channel in Golang
- Interfaces in Golang
- Methods in Golang
- Methods With Same Name in Golang
- Hello World in Golang
- Encapsulation in Golang
- Rune in Golang
- Closures in Golang
- Packages in Golang
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : pradeepjangidcse15