Standard library / runtime/debug
debug.SetMaxThreads()
Limits OS threads, not goroutines. Exceeding the limit is fatal; do not use as a concurrency semaphore. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func SetMaxThreads(threads int) intParameters & Attributes
| Name | Type | Description |
|---|---|---|
| threads | int | New maximum OS-thread count; exceeding it can terminate the program. |
Return Value
int
Previous maximum OS-thread count.
Working Example
Example Snippetgo
package main
import ( "fmt" "runtime/debug")
func main() { old := debug.SetMaxThreads(10000); defer debug.SetMaxThreads(old); fmt.Println(old > 0) }