1 // Copyright 2023 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 //go:build !plan9 && !windows
7 // Test that callbacks from C to Go in the same C-thread always get the same m.
8 // Make sure the extra M bind to the C-thread.
13 extern void CheckBindM();
27 cThreadToM = map[uintptr]uintptr{}
28 started = atomic.Uint32{}
31 // same as CTHREADS in C, make sure all the C threads are actually started.
35 register("EnsureBindM", EnsureBindM)
39 func GoCheckBindM(thread uintptr) {
40 // Wait all threads start
41 if started.Load() != cThreadNum {
42 // Only once for each thread, since it will wait all threads start.
44 for started.Load() < cThreadNum {
48 m := runtime_getm_for_test()
51 if savedM, ok := cThreadToM[thread]; ok && savedM != m {
52 fmt.Printf("m == %x want %x\n", m, savedM)
55 cThreadToM[thread] = m