]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: clear preemptStop in dropm
authorIan Lance Taylor <iant@golang.org>
Sat, 2 Nov 2019 00:53:53 +0000 (17:53 -0700)
committerIan Lance Taylor <iant@golang.org>
Sat, 2 Nov 2019 05:52:33 +0000 (05:52 +0000)
Updates #10958
Updates #24543
Fixes #35294

Change-Id: I60f024d08451565df6d9751dab9832b50cbf637a
Reviewed-on: https://go-review.googlesource.com/c/go/+/204957
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
misc/cgo/testcarchive/carchive_test.go
misc/cgo/testcarchive/testdata/libgo7/sink.go [new file with mode: 0644]
misc/cgo/testcarchive/testdata/main7.c [new file with mode: 0644]
src/runtime/proc.go

index 739bfe42bf56fa873c711b97cd9f1ce421dde3bd..cf2c6264dd179f97f5645550cee3548bbd2a48e5 100644 (file)
@@ -813,3 +813,52 @@ func TestCachedInstall(t *testing.T) {
                t.Errorf("p.h not installed in second run: %v", err)
        }
 }
+
+// Issue 35294.
+func TestManyCalls(t *testing.T) {
+       t.Parallel()
+
+       defer func() {
+               os.Remove("testp7" + exeSuffix)
+               os.Remove("libgo7.a")
+               os.Remove("libgo7.h")
+       }()
+
+       cmd := exec.Command("go", "build", "-buildmode=c-archive", "-o", "libgo7.a", "./libgo7")
+       if out, err := cmd.CombinedOutput(); err != nil {
+               t.Logf("%s", out)
+               t.Fatal(err)
+       }
+       checkLineComments(t, "libgo7.h")
+
+       ccArgs := append(cc, "-o", "testp7"+exeSuffix, "main7.c", "libgo7.a")
+       if runtime.Compiler == "gccgo" {
+               ccArgs = append(ccArgs, "-lgo")
+       }
+       if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
+               t.Logf("%s", out)
+               t.Fatal(err)
+       }
+
+       argv := cmdToRun("./testp7")
+       cmd = exec.Command(argv[0], argv[1:]...)
+       var sb strings.Builder
+       cmd.Stdout = &sb
+       cmd.Stderr = &sb
+       if err := cmd.Start(); err != nil {
+               t.Fatal(err)
+       }
+
+       timer := time.AfterFunc(time.Minute,
+               func() {
+                       t.Error("test program timed out")
+                       cmd.Process.Kill()
+               },
+       )
+       defer timer.Stop()
+
+       if err := cmd.Wait(); err != nil {
+               t.Log(sb.String())
+               t.Error(err)
+       }
+}
diff --git a/misc/cgo/testcarchive/testdata/libgo7/sink.go b/misc/cgo/testcarchive/testdata/libgo7/sink.go
new file mode 100644 (file)
index 0000000..d61638b
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2019 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 "C"
+
+var sink []byte
+
+//export GoFunction7
+func GoFunction7() {
+       sink = make([]byte, 4096)
+}
+
+func main() {
+}
diff --git a/misc/cgo/testcarchive/testdata/main7.c b/misc/cgo/testcarchive/testdata/main7.c
new file mode 100644 (file)
index 0000000..3d10109
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2019 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.
+
+// Test that lots of calls don't deadlock.
+
+#include <stdio.h>
+
+#include "libgo7.h"
+
+int main() {
+       int i;
+
+       for (i = 0; i < 100000; i++) {
+               GoFunction7();
+       }
+}
index f9a22ca5e3faa8b13d8b53077dcc2412f1e4f338..6740169cf8ed2bff32b401051914a66ec1dc0276 100644 (file)
@@ -1625,6 +1625,7 @@ func dropm() {
 
        // Return mp.curg to dead state.
        casgstatus(mp.curg, _Gsyscall, _Gdead)
+       mp.curg.preemptStop = false
        atomic.Xadd(&sched.ngsys, +1)
 
        // Block signals before unminit.