diff options
author | Russ Cox <rsc@golang.org> | 2014-10-28 21:53:09 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2014-10-28 21:53:09 -0400 |
commit | a2e462d0c57834122b1911248c7ed4276879c427 (patch) | |
tree | 364c00c66d831d15fffc14e2e707b6d7c4b04fbe /src/runtime/crash_cgo_test.go | |
parent | 1c82a606a42bca5c13cbacd80df1800197ee5f21 (diff) | |
download | go-a2e462d0c57834122b1911248c7ed4276879c427.tar.gz |
runtime: fix unrecovered panic on external thread
Fixes issue 8588.
LGTM=austin
R=austin
CC=golang-codereviews, khr
https://codereview.appspot.com/159700044
Diffstat (limited to 'src/runtime/crash_cgo_test.go')
-rw-r--r-- | src/runtime/crash_cgo_test.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/runtime/crash_cgo_test.go b/src/runtime/crash_cgo_test.go index 4ff0084c2..787796558 100644 --- a/src/runtime/crash_cgo_test.go +++ b/src/runtime/crash_cgo_test.go @@ -8,6 +8,7 @@ package runtime_test import ( "runtime" + "strings" "testing" ) @@ -34,6 +35,14 @@ func TestCgoTraceback(t *testing.T) { } } +func TestCgoExternalThreadPanic(t *testing.T) { + got := executeTest(t, cgoExternalThreadPanicSource, nil, "main.c", cgoExternalThreadPanicC) + want := "panic: BOOM" + if !strings.Contains(got, want) { + t.Fatalf("want failure containing %q. output:\n%s\n", want, got) + } +} + const cgoSignalDeadlockSource = ` package main @@ -117,3 +126,43 @@ func main() { fmt.Printf("OK\n") } ` + +const cgoExternalThreadPanicSource = ` +package main + +// void start(void); +import "C" + +func main() { + C.start() + select {} +} + +//export gopanic +func gopanic() { + panic("BOOM") +} +` + +const cgoExternalThreadPanicC = ` +#include <stdlib.h> +#include <stdio.h> +#include <pthread.h> + +void gopanic(void); + +static void* +die(void* x) +{ + gopanic(); + return 0; +} + +void +start(void) +{ + pthread_t t; + if(pthread_create(&t, 0, die, 0) != 0) + printf("pthread_create failed\n"); +} +` |