# Goroutine
The [[Green thread]] construct used in [[golang]] for [[Concurrency]].
From [[PAPER - Understanding Real-World Concurrency Bugs in Go]]:
> Goroutines are lightweight user-level threads that the go runtime library manages and maps to kernel-level threads in an M-to-N way. A goroutine can be created by simply adding the keyword `go` before a function call.
> [!warning] See [[ZK - 2g3a - golang Concurrency is not easy]], as it goes more into how the ease of using the `go` keyword in [[golang]] can easily be harmful (as I learned [[Refactoring]] [[richard-nixon walkthrough]]).
Goroutines are often using in conjunction with [[golang channels]] in order to do [[Message passing]].
## Snippets
- [[SNIPPET - golang - List goroutines and print mem usage]]
- [[SNIPPET - golang - HUP signal stacktrace printer]]
## Links
A great video about the implementation of the [[golang]] [[Scheduler]] implementation by [[Dmitry Vyuokov]] from [[Google]]. It goes deep into scalability and fairness.
- [Go Scheduler: Implementing language with lightweight concurrency](https://youtu.be/-K11rY57K7k)
This article goes through finding a [[Deadlock]] problem in a "simple" loop with [[Rate-limiting]] channel. [[Hillel Wayne]] uses [[TLA+]] to apply [[Formal Methods]] for finding [[Concurrency]] bugs in that piece of [[golang]] code:
- [Finding Goroutine Bugs with TLA+ • Hillel Wayne](https://www.hillelwayne.com/post/tla-golang/)