diff options
author | Michael Pratt <mpratt@google.com> | 2023-04-17 14:13:06 -0400 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2023-04-17 18:47:08 +0000 |
commit | 94850c6f79a68b3f061c9e29d48603afa37df194 (patch) | |
tree | 71d8c5e09d4da8ab5b521559b7584c0060f33642 /misc | |
parent | 97e5ca6d4eed7b14a4dbdd52aa4e934028284993 (diff) | |
download | go-git-94850c6f79a68b3f061c9e29d48603afa37df194.tar.gz |
Revert "runtime/cgo: store M for C-created thread in pthread key"
This reverts CL 481061.
Reason for revert: When built with C TSAN, x_cgo_getstackbound triggers
race detection on `g->stacklo` because the synchronization is in Go,
which isn't instrumented.
For #51676.
For #59294.
For #59678.
Change-Id: I38afcda9fcffd6537582a39a5214bc23dc147d47
Reviewed-on: https://go-review.googlesource.com/c/go/+/485275
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'misc')
-rw-r--r-- | misc/cgo/test/cgo_test.go | 7 | ||||
-rw-r--r-- | misc/cgo/test/cthread_unix.c | 24 | ||||
-rw-r--r-- | misc/cgo/test/cthread_windows.c | 22 | ||||
-rw-r--r-- | misc/cgo/test/testx.go | 14 | ||||
-rw-r--r-- | misc/cgo/testcarchive/carchive_test.go | 54 | ||||
-rw-r--r-- | misc/cgo/testcarchive/testdata/libgo9/a.go | 14 | ||||
-rw-r--r-- | misc/cgo/testcarchive/testdata/main9.c | 24 |
7 files changed, 3 insertions, 156 deletions
diff --git a/misc/cgo/test/cgo_test.go b/misc/cgo/test/cgo_test.go index 0c3980c12d..5b298954f5 100644 --- a/misc/cgo/test/cgo_test.go +++ b/misc/cgo/test/cgo_test.go @@ -104,7 +104,6 @@ func TestThreadLock(t *testing.T) { testThreadLockFunc(t) } func TestUnsignedInt(t *testing.T) { testUnsignedInt(t) } func TestZeroArgCallback(t *testing.T) { testZeroArgCallback(t) } -func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) } -func BenchmarkGoString(b *testing.B) { benchGoString(b) } -func BenchmarkCGoCallback(b *testing.B) { benchCallback(b) } -func BenchmarkCGoInCThread(b *testing.B) { benchCGoInCthread(b) } +func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) } +func BenchmarkGoString(b *testing.B) { benchGoString(b) } +func BenchmarkCGoCallback(b *testing.B) { benchCallback(b) } diff --git a/misc/cgo/test/cthread_unix.c b/misc/cgo/test/cthread_unix.c index d0da643158..b6ec39816b 100644 --- a/misc/cgo/test/cthread_unix.c +++ b/misc/cgo/test/cthread_unix.c @@ -32,27 +32,3 @@ doAdd(int max, int nthread) for(i=0; i<nthread; i++) pthread_join(thread_id[i], 0); } - -static void* -goDummyCallbackThread(void* p) -{ - int i, max; - - max = *(int*)p; - for(i=0; i<max; i++) - goDummy(); - return NULL; -} - -int -callGoInCThread(int max) -{ - pthread_t thread; - - if (pthread_create(&thread, NULL, goDummyCallbackThread, (void*)(&max)) != 0) - return -1; - if (pthread_join(thread, NULL) != 0) - return -1; - - return max; -} diff --git a/misc/cgo/test/cthread_windows.c b/misc/cgo/test/cthread_windows.c index 4e52209dee..3a62ddd373 100644 --- a/misc/cgo/test/cthread_windows.c +++ b/misc/cgo/test/cthread_windows.c @@ -35,25 +35,3 @@ doAdd(int max, int nthread) CloseHandle((HANDLE)thread_id[i]); } } - -__stdcall -static unsigned int -goDummyCallbackThread(void* p) -{ - int i, max; - - max = *(int*)p; - for(i=0; i<max; i++) - goDummy(); - return 0; -} - -int -callGoInCThread(int max) -{ - uintptr_t thread_id; - thread_id = _beginthreadex(0, 0, goDummyCallbackThread, &max, 0, 0); - WaitForSingleObject((HANDLE)thread_id, INFINITE); - CloseHandle((HANDLE)thread_id); - return max; -} diff --git a/misc/cgo/test/testx.go b/misc/cgo/test/testx.go index 0e2a51a522..6a8e97ddf3 100644 --- a/misc/cgo/test/testx.go +++ b/misc/cgo/test/testx.go @@ -24,7 +24,6 @@ import ( /* // threads extern void doAdd(int, int); -extern int callGoInCThread(int); // issue 1328 void IntoC(void); @@ -147,10 +146,6 @@ func Add(x int) { *p = 2 } -//export goDummy -func goDummy() { -} - func testCthread(t *testing.T) { if (runtime.GOOS == "darwin" || runtime.GOOS == "ios") && runtime.GOARCH == "arm64" { t.Skip("the iOS exec wrapper is unable to properly handle the panic from Add") @@ -164,15 +159,6 @@ func testCthread(t *testing.T) { } } -// Benchmark measuring overhead from C to Go in a C thread. -// Create a new C thread and invoke Go function repeatedly in the new C thread. -func benchCGoInCthread(b *testing.B) { - n := C.callGoInCThread(C.int(b.N)) - if int(n) != b.N { - b.Fatal("unmatch loop times") - } -} - // issue 1328 //export BackIntoGo diff --git a/misc/cgo/testcarchive/carchive_test.go b/misc/cgo/testcarchive/carchive_test.go index 5996268018..8a39c24a6d 100644 --- a/misc/cgo/testcarchive/carchive_test.go +++ b/misc/cgo/testcarchive/carchive_test.go @@ -1247,57 +1247,3 @@ func TestPreemption(t *testing.T) { t.Error(err) } } - -// Issue 59294. Test calling Go function from C after using some -// stack space. -func TestDeepStack(t *testing.T) { - t.Parallel() - - if !testWork { - defer func() { - os.Remove("testp9" + exeSuffix) - os.Remove("libgo9.a") - os.Remove("libgo9.h") - }() - } - - cmd := exec.Command("go", "build", "-buildmode=c-archive", "-o", "libgo9.a", "./libgo9") - out, err := cmd.CombinedOutput() - t.Logf("%v\n%s", cmd.Args, out) - if err != nil { - t.Fatal(err) - } - checkLineComments(t, "libgo9.h") - checkArchive(t, "libgo9.a") - - // build with -O0 so the C compiler won't optimize out the large stack frame - ccArgs := append(cc, "-O0", "-o", "testp9"+exeSuffix, "main9.c", "libgo9.a") - out, err = exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput() - t.Logf("%v\n%s", ccArgs, out) - if err != nil { - t.Fatal(err) - } - - argv := cmdToRun("./testp9") - cmd = exec.Command(argv[0], argv[1:]...) - sb := new(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() - - err = cmd.Wait() - t.Logf("%v\n%s", cmd.Args, sb) - if err != nil { - t.Error(err) - } -} diff --git a/misc/cgo/testcarchive/testdata/libgo9/a.go b/misc/cgo/testcarchive/testdata/libgo9/a.go deleted file mode 100644 index acb08d90ec..0000000000 --- a/misc/cgo/testcarchive/testdata/libgo9/a.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2023 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" - -import "C" - -func main() {} - -//export GoF -func GoF() { runtime.GC() } diff --git a/misc/cgo/testcarchive/testdata/main9.c b/misc/cgo/testcarchive/testdata/main9.c deleted file mode 100644 index 95ad4dea49..0000000000 --- a/misc/cgo/testcarchive/testdata/main9.c +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2023 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. - -#include "libgo9.h" - -void use(int *x) { (*x)++; } - -void callGoFWithDeepStack() { - int x[10000]; - - use(&x[0]); - use(&x[9999]); - - GoF(); - - use(&x[0]); - use(&x[9999]); -} - -int main() { - GoF(); // call GoF without using much stack - callGoFWithDeepStack(); // call GoF with a deep stack -} |