As asked
What is the difference between a goroutine and an OS thread in terms of memory, creation cost, and how they are scheduled? How many goroutines can a typical Go program run concurrently?
Sample answer outline
A strong answer covers that goroutines start with a small growable stack (2 KB versus 8 MB default for OS threads), are cheaper to create (microseconds versus milliseconds), and are scheduled cooperatively/preemptively by the Go runtime rather than the OS kernel. The scheduler multiplexes many goroutines onto a small number of OS threads. A typical program can run hundreds of thousands to millions of goroutines depending on their stack size and available memory.
Expect these follow-ups
- What limits how many goroutines you can practically create in a single process?
- How does goroutine stack growth work when a goroutine needs more than its initial allocation?