]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: sleep in TestSegv program to let signal be delivered
authorIan Lance Taylor <iant@golang.org>
Wed, 22 Apr 2020 23:03:30 +0000 (16:03 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 24 Apr 2020 22:23:04 +0000 (22:23 +0000)
Since we're sleeping rather than waiting for the goroutines,
let the goroutines run forever.

Fixes #38595

Change-Id: I4cd611fd7565f6e8d91e50c9273d91c514825314
Reviewed-on: https://go-review.googlesource.com/c/go/+/229484
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/runtime/testdata/testprogcgo/segv.go

index 77e75f276a5257a4a12aed9d9dfe81f7ec6fbdf9..3237a8c69c6f36d491a05159794fc25710b17907 100644 (file)
@@ -10,8 +10,8 @@ package main
 import "C"
 
 import (
-       "sync"
        "syscall"
+       "time"
 )
 
 func init() {
@@ -23,12 +23,9 @@ var Sum int
 
 func Segv() {
        c := make(chan bool)
-       var wg sync.WaitGroup
-       wg.Add(1)
        go func() {
-               defer wg.Done()
                close(c)
-               for i := 0; i < 10000; i++ {
+               for i := 0; ; i++ {
                        Sum += i
                }
        }()
@@ -37,17 +34,15 @@ func Segv() {
 
        syscall.Kill(syscall.Getpid(), syscall.SIGSEGV)
 
-       wg.Wait()
+       // Give the OS time to deliver the signal.
+       time.Sleep(time.Second)
 }
 
 func SegvInCgo() {
        c := make(chan bool)
-       var wg sync.WaitGroup
-       wg.Add(1)
        go func() {
-               defer wg.Done()
                close(c)
-               for i := 0; i < 10000; i++ {
+               for {
                        C.nop()
                }
        }()
@@ -56,5 +51,6 @@ func SegvInCgo() {
 
        syscall.Kill(syscall.Getpid(), syscall.SIGSEGV)
 
-       wg.Wait()
+       // Give the OS time to deliver the signal.
+       time.Sleep(time.Second)
 }