From 72c33a5ef0eea8663328375d9d339ed150310ebb Mon Sep 17 00:00:00 2001 From: Chressie Himpel Date: Fri, 5 May 2023 14:17:38 +0000 Subject: Revert "runtime/cgo: store M for C-created thread in pthread key" This reverts CL 485500. Reason for revert: This breaks internal tests at Google, see b/280861579 and b/280820455. Change-Id: I426278d400f7611170918fc07c524cb059b9cc55 Reviewed-on: https://go-review.googlesource.com/c/go/+/492995 Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot Run-TryBot: Chressie Himpel --- src/runtime/testdata/testprogcgo/bindm.c | 34 ----------------- src/runtime/testdata/testprogcgo/bindm.go | 61 ------------------------------- 2 files changed, 95 deletions(-) delete mode 100644 src/runtime/testdata/testprogcgo/bindm.c delete mode 100644 src/runtime/testdata/testprogcgo/bindm.go (limited to 'src/runtime/testdata') diff --git a/src/runtime/testdata/testprogcgo/bindm.c b/src/runtime/testdata/testprogcgo/bindm.c deleted file mode 100644 index 815d8a75f2..0000000000 --- a/src/runtime/testdata/testprogcgo/bindm.c +++ /dev/null @@ -1,34 +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. - -//go:build !plan9 && !windows - -#include -#include -#include -#include "_cgo_export.h" - -#define CTHREADS 2 -#define CHECKCALLS 100 - -static void* checkBindMThread(void* thread) { - int i; - for (i = 0; i < CHECKCALLS; i++) { - GoCheckBindM((uintptr_t)thread); - usleep(1); - } - return NULL; -} - -void CheckBindM() { - int i; - pthread_t s[CTHREADS]; - - for (i = 0; i < CTHREADS; i++) { - pthread_create(&s[i], NULL, checkBindMThread, &s[i]); - } - for (i = 0; i < CTHREADS; i++) { - pthread_join(s[i], NULL); - } -} diff --git a/src/runtime/testdata/testprogcgo/bindm.go b/src/runtime/testdata/testprogcgo/bindm.go deleted file mode 100644 index c2003c2093..0000000000 --- a/src/runtime/testdata/testprogcgo/bindm.go +++ /dev/null @@ -1,61 +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. - -//go:build !plan9 && !windows - -// Test that callbacks from C to Go in the same C-thread always get the same m. -// Make sure the extra M bind to the C-thread. - -package main - -/* -extern void CheckBindM(); -*/ -import "C" - -import ( - "fmt" - "os" - "runtime" - "sync" - "sync/atomic" -) - -var ( - mutex = sync.Mutex{} - cThreadToM = map[uintptr]uintptr{} - started = atomic.Uint32{} -) - -// same as CTHREADS in C, make sure all the C threads are actually started. -const cThreadNum = 2 - -func init() { - register("EnsureBindM", EnsureBindM) -} - -//export GoCheckBindM -func GoCheckBindM(thread uintptr) { - // Wait all threads start - if started.Load() != cThreadNum { - // Only once for each thread, since it will wait all threads start. - started.Add(1) - for started.Load() < cThreadNum { - runtime.Gosched() - } - } - m := runtime_getm_for_test() - mutex.Lock() - defer mutex.Unlock() - if savedM, ok := cThreadToM[thread]; ok && savedM != m { - fmt.Printf("m == %x want %x\n", m, savedM) - os.Exit(1) - } - cThreadToM[thread] = m -} - -func EnsureBindM() { - C.CheckBindM() - fmt.Println("OK") -} -- cgit v1.3