go crashdump 源码

  • 2022-07-15
  • 浏览 (790)

golang crashdump 代码

文件路径:/src/runtime/testdata/testprog/crashdump.go

// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"fmt"
	"os"
	"runtime"
)

func init() {
	register("CrashDumpsAllThreads", CrashDumpsAllThreads)
}

func CrashDumpsAllThreads() {
	const count = 4
	runtime.GOMAXPROCS(count + 1)

	chans := make([]chan bool, count)
	for i := range chans {
		chans[i] = make(chan bool)
		go crashDumpsAllThreadsLoop(i, chans[i])
	}

	// Wait for all the goroutines to start executing.
	for _, c := range chans {
		<-c
	}

	// Tell our parent that all the goroutines are executing.
	if _, err := os.NewFile(3, "pipe").WriteString("x"); err != nil {
		fmt.Fprintf(os.Stderr, "write to pipe failed: %v\n", err)
		os.Exit(2)
	}

	select {}
}

func crashDumpsAllThreadsLoop(i int, c chan bool) {
	close(c)
	for {
		for j := 0; j < 0x7fffffff; j++ {
		}
	}
}

相关信息

go 源码目录

相关文章

go abort 源码

go badtraceback 源码

go checkptr 源码

go crash 源码

go deadlock 源码

go gc 源码

go lockosthread 源码

go main 源码

go map 源码

go memprof 源码

0  赞