运行时: LockOSThread 包装注册表调用时出现堆栈损坏(在 Go 1.27 中新增)
// Repro: stack corruption on windows/amd64 with Go 1.27.x. // // Worker goroutines call runtime.LockOSThread, make Windows system calls, // and unlock, while 16 other goroutines send on a channel and allocate. // // LOCK=1 (default) lock the OS thread around the system calls // LOCK=0 same work without LockOSThread // WORK=registry enumerate and open subkeys of HKLM/HKCU Uninstall (default) // WORK=syscall call GetCurrentProcessId repeatedly instead package main
import ( "fmt" "os" "runtime" "strings" "sync/atomic" "syscall" "time" )
// openKey opens a key in the registry. If the key does not exist, // it is created. If the key is not a subkey of the given parent, // it is created as a subkey of the parent. If the key is a subkey // of the given parent, it is opened. If the key is not a subkey // of the given parent, it is opened as a subkey of the parent. func openKey(parent syscall.Handle, path string, access uint32) (syscall.Handle, bool) { p, err := syscall.UTF16PtrFromString(path) if err != nil { return 0, false } var k syscall.Handle return k, syscall.RegOpenKeyEx(parent, p, 0, access, &k) == nil }
// subkeyNames returns the names of the subkeys of the given key. func subkeyNames(k syscall.Handle) []string { if lock { runtime.LockOSThread() defer runtime.UnlockOSThread() } var names []string buf := make([]uint16, 256) for i := uint32(0); ; i++ { n := …
内容来源: golang/go