Junior — Middle
What is the maximum number of stacks a goroutine can have at the same time?
sobes.tech AI
Answer from AI
Goroutines in Go have a dynamically expanding stack, which is initially very small — usually around 2 KB. The maximum stack size is not fixed and is limited only by available memory and runtime settings.
Thus, each goroutine has one stack, but its size can grow as needed. This allows thousands or even millions of goroutines to run simultaneously, since the initial stack size is very small.
Example:
func main() {
go func() {
// goroutine with a small stack
}()
}