Standard library / runtime/debug
debug.SetMaxStack()
Limits future growth of an individual goroutine stack; exceeding the limit can crash the process. This example changes and restores a generous limit, not a crash test. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func SetMaxStack(bytes int) intParameters & Attributes
| Name | Type | Description |
|---|---|---|
| bytes | int | New per-goroutine stack size limit in bytes. |
Return Value
int
Previous maximum stack size in bytes.
Working Example
Example Snippetgo
package main
import ( "fmt" "runtime/debug")
func main() { old := debug.SetMaxStack(512 << 20); defer debug.SetMaxStack(old); fmt.Println(old > 0) }