Documentation ¶
Overview ¶
Package mkill limits the number of threads in a Go program, without crash the whole program.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GOMAXTHREADS ¶
GOMAXTHREADS sets the maximum number of system threads that allowed in a Go program and returns the previous setting. If n is lower than minimum required number of threads, it does not change the current setting. The minimum allowed number of threads of a program is runtime.NumCPU() + 2.
Example ¶
package main import ( "golang.design/x/mkill" ) func main() { mkill.GOMAXTHREADS(10) }
Output:
func NumM ¶
func NumM() int
NumM returns the number of running threads.
Example ¶
package main import ( "context" "fmt" "golang.design/x/mkill" ) func main() { mkill.GOMAXTHREADS(10) mkill.Wait(context.Background()) fmt.Println(mkill.NumM() <= 10) }
Output: true
func Wait ¶
Wait waits until the number of threads meet the GOMAXTHREADS settings. The function always returns true if the ctx is not canceled. Otherwise returns true only if the Wait is successed in the last check.
Example ¶
package main import ( "context" "fmt" "time" "golang.design/x/mkill" ) func main() { mkill.GOMAXTHREADS(10) ctx, cancel := context.WithTimeout(context.Background(), time.Second*100) defer cancel() fmt.Println(mkill.Wait(ctx)) }
Output: true
Types ¶
This section is empty.