¿Por qué la pila de gorutinas es infinita?

De vez en cuando, los recién llegados a Go se topan con una propiedad de lenguaje interesante relacionada con el tamaño de pila disponible para una goroutine. Esto suele suceder porque el programador crea inadvertidamente una recursividad infinita. Para ilustrar esto, considere el siguiente ejemplo (ligeramente elaborado).







package main

import "fmt"

type S struct {
        a, b int
}

// String implements the fmt.Stringer interface
func (s *S) String() string {
        return fmt.Sprintf("%s", s) // Sprintf will call s.String()
}

func main() {
        s := &S{a: 1, b: 2}
        fmt.Println(s)
}
      
      





, , , , , , ^C , . , , , .







, , , . , , Go?







— ; ( 1–8 POSIX), . 4096 ( Go 2048 — . ), - .







, (5l, 6l, 8l) "" [1], , . , , , runtime morestack, [2], (caller), , . , , , .







Go , , , .







, , , Go , .







, , . , .







, Go, , , , , , , .







Go 1.1 32-, 64- , , .. , 128 [3] .







, (, ), , , , .







. : (2013 ) Go , 1 GB 64 250 MB 32.









  1. , , , .
  2. «» , 4096 , runtime⋅morestack , , .
  3. 64- Windows 32 - Go 1.1.



All Articles