1// run 2 3// Copyright 2014 The Go Authors. All rights reserved. 4// Use of this source code is governed by a BSD-style 5// license that can be found in the LICENSE file. 6 7package main 8 9import ( 10 "runtime" 11 "time" 12) 13 14func main() { 15 c := make(chan bool, 1) 16 go f1(c) 17 <-c 18 time.Sleep(10 * time.Millisecond) 19 go f2(c) 20 <-c 21} 22 23func f1(done chan bool) { 24 defer func() { 25 recover() 26 done <- true 27 runtime.Goexit() // left stack-allocated Panic struct on gp->panic stack 28 }() 29 panic("p") 30} 31 32func f2(done chan bool) { 33 defer func() { 34 recover() 35 done <- true 36 runtime.Goexit() 37 }() 38 time.Sleep(10 * time.Millisecond) // overwrote Panic struct with Timer struct 39 runtime.GC() // walked gp->panic list, found mangled Panic struct, crashed 40 panic("p") 41} 42