...
1
2
3
4
5
6
7
8
9
10 package main
11
12
15 import "C"
16
17 import (
18 "fmt"
19 "os"
20 "runtime"
21 "sync"
22 "sync/atomic"
23 )
24
25 var (
26 mutex = sync.Mutex{}
27 cThreadToM = map[uintptr]uintptr{}
28 started = atomic.Uint32{}
29 )
30
31
32 const cThreadNum = 2
33
34 func init() {
35 register("EnsureBindM", EnsureBindM)
36 }
37
38
39 func GoCheckBindM(thread uintptr) {
40
41 if started.Load() != cThreadNum {
42
43 started.Add(1)
44 for started.Load() < cThreadNum {
45 runtime.Gosched()
46 }
47 }
48 m := runtime_getm_for_test()
49 mutex.Lock()
50 defer mutex.Unlock()
51 if savedM, ok := cThreadToM[thread]; ok && savedM != m {
52 fmt.Printf("m == %x want %x\n", m, savedM)
53 os.Exit(1)
54 }
55 cThreadToM[thread] = m
56 }
57
58 func EnsureBindM() {
59 C.CheckBindM()
60 fmt.Println("OK")
61 }
62
View as plain text