Por que a pilha goroutine é infinita?

De vez em quando, os novatos em Go se deparam com uma propriedade de linguagem interessante relacionada ao tamanho da pilha disponível para uma goroutine. Isso geralmente acontece porque o programador cria inadvertidamente uma recursão infinita. Para ilustrar isso, considere o seguinte exemplo (ligeiramente artificial).







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