mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: impose thread count limit
Actually working to stay within the limit could cause subtle deadlocks. Crashing avoids the subtlety. Fixes #4056. R=golang-dev, r, dvyukov CC=golang-dev https://golang.org/cl/13037043
This commit is contained in:
parent
3b4d792606
commit
665feeedcb
3 changed files with 74 additions and 1 deletions
|
|
@ -125,6 +125,14 @@ func TestStackOverflow(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestThreadExhaustion(t *testing.T) {
|
||||
output := executeTest(t, threadExhaustionSource, nil)
|
||||
want := "runtime: program exceeds 10-thread limit\nfatal error: thread exhaustion"
|
||||
if !strings.HasPrefix(output, want) {
|
||||
t.Fatalf("output does not start with %q:\n%s", want, output)
|
||||
}
|
||||
}
|
||||
|
||||
const crashSource = `
|
||||
package main
|
||||
|
||||
|
|
@ -243,3 +251,25 @@ func f(x []byte) byte {
|
|||
return x[0] + f(buf[:])
|
||||
}
|
||||
`
|
||||
|
||||
const threadExhaustionSource = `
|
||||
package main
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
debug.SetMaxThreads(10)
|
||||
c := make(chan int)
|
||||
for i := 0; i < 100; i++ {
|
||||
go func() {
|
||||
runtime.LockOSThread()
|
||||
c <- 0
|
||||
select{}
|
||||
}()
|
||||
<-c
|
||||
}
|
||||
}
|
||||
`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue