Source file src/runtime/testdata/testprog/crashdump.go

     1  // Copyright 2021 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"os"
    10  	"runtime"
    11  )
    12  
    13  func init() {
    14  	register("CrashDumpsAllThreads", CrashDumpsAllThreads)
    15  }
    16  
    17  func CrashDumpsAllThreads() {
    18  	const count = 4
    19  	runtime.GOMAXPROCS(count + 1)
    20  
    21  	chans := make([]chan bool, count)
    22  	for i := range chans {
    23  		chans[i] = make(chan bool)
    24  		go crashDumpsAllThreadsLoop(i, chans[i])
    25  	}
    26  
    27  	// Wait for all the goroutines to start executing.
    28  	for _, c := range chans {
    29  		<-c
    30  	}
    31  
    32  	// Tell our parent that all the goroutines are executing.
    33  	if _, err := os.NewFile(3, "pipe").WriteString("x"); err != nil {
    34  		fmt.Fprintf(os.Stderr, "write to pipe failed: %v\n", err)
    35  		os.Exit(2)
    36  	}
    37  
    38  	select {}
    39  }
    40  
    41  func crashDumpsAllThreadsLoop(i int, c chan bool) {
    42  	close(c)
    43  	for {
    44  		for j := 0; j < 0x7fffffff; j++ {
    45  		}
    46  	}
    47  }
    48  

View as plain text