基于 CGO 实现的一些辅助工具
go >= 1.24.2- GCC 10 +, 在 Windows 平台上需要等价版本的 MinGW
go get github.com/focusingly/cgo-kitimport (
"context"
"testing"
"time"
v1 "github.com/focusingly/cgo-kit/v1"
)
const (
coreSelector = 0
)
func TestCoreLock(t *testing.T) {
ctx, cancel := context.WithTimeout(t.Context(), time.Second*20)
var i uint64
go func() {
defer cancel()
cleanup, err := v1.LockThreadToCore(coreSelector)
if err != nil {
t.Logf("lock park core fault: %s", err.Error())
t.Fail()
}
defer cleanup()
for {
select {
case <-ctx.Done():
return
default:
// spin
i++
}
}
}()
<-ctx.Done() // Pass Test
}