27 lines
603 B
Go
27 lines
603 B
Go
// Thread bomb: 256 goroutines blocked in system calls force the runtime to
|
|
// create an OS thread for each; the cgroup process limit must stop it. The
|
|
// goroutine count is bounded so that their stacks stay far below the memory
|
|
// limit and the process limit is always the one that stops the program.
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
const blockedGoroutines = 256
|
|
|
|
func main() {
|
|
var fds [2]int
|
|
if err := syscall.Pipe(fds[:]); err != nil {
|
|
os.Exit(2)
|
|
}
|
|
for range blockedGoroutines {
|
|
go func() {
|
|
buffer := make([]byte, 1)
|
|
_, _ = syscall.Read(fds[0], buffer)
|
|
}()
|
|
}
|
|
select {}
|
|
}
|