Warum ist der Goroutine-Stapel unendlich?

Von Zeit zu Zeit stoßen Neulinge auf eine interessante Spracheigenschaft, die sich auf die Stapelgröße bezieht, die einer Goroutine zur Verfügung steht. Dies geschieht normalerweise, weil der Programmierer versehentlich eine unendliche Rekursion erzeugt. Betrachten Sie zur Veranschaulichung das folgende (leicht erfundene) Beispiel.







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