aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/testdata/testprog
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2017-04-19 07:32:34 -0700
committerIan Lance Taylor <iant@golang.org>2017-06-05 22:42:48 +0000
commit2d86f4942868c1309051062237cf4d424d588e9c (patch)
tree83daa9155317bed206497703c0132b1bfc4a0265 /src/runtime/testdata/testprog
parent3c745d750e8342b1dd4144a83488b559efb8b271 (diff)
downloadgo-2d86f4942868c1309051062237cf4d424d588e9c.tar.xz
runtime: delay exiting while panic is running deferred functions
Try to avoid a race between the main goroutine exiting and a panic occurring. Don't try too hard, to avoid hanging. Updates #3934 Fixes #20018 Change-Id: I57a02b6d795d2a61f1cadd137ce097145280ece7 Reviewed-on: https://go-review.googlesource.com/41052 Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/testdata/testprog')
-rw-r--r--src/runtime/testdata/testprog/panicrace.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/runtime/testdata/testprog/panicrace.go b/src/runtime/testdata/testprog/panicrace.go
new file mode 100644
index 0000000000..f0589940b5
--- /dev/null
+++ b/src/runtime/testdata/testprog/panicrace.go
@@ -0,0 +1,27 @@
+// Copyright 2017 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 (
+ "runtime"
+ "sync"
+)
+
+func init() {
+ register("PanicRace", PanicRace)
+}
+
+func PanicRace() {
+ var wg sync.WaitGroup
+ wg.Add(1)
+ go func() {
+ defer func() {
+ wg.Done()
+ runtime.Gosched()
+ }()
+ panic("crash")
+ }()
+ wg.Wait()
+}