This test
diff --git a/src/pkg/runtime/syscall_windows_test.go
b/src/pkg/runtime/syscall_windows_test.go
--- a/src/pkg/runtime/syscall_windows_test.go
+++ b/src/pkg/runtime/syscall_windows_test.go
@@ -240,5 +240,35 @@
}
func TestCallbackInAnotherThread(t *testing.T) {
- // TODO: test a function which calls back in another thread: QueueUserAPC() or
CreateThread()
+ d := GetDLL(t, "kernel32.dll")
+
+ f := func(p uintptr) uintptr {
+ return p
+ }
+ r, _, err := d.Proc("CreateThread").Call(0, 0, syscall.NewCallback(f), 123,
0, 0)
+ if r == 0 {
+ t.Fatalf("CreateThread failed: %v", err)
+ }
+ h := syscall.Handle(r)
+ defer syscall.CloseHandle(h)
+
+ switch s, err := syscall.WaitForSingleObject(h, 100); s {
+ case syscall.WAIT_OBJECT_0:
+ break
+ case syscall.WAIT_TIMEOUT:
+ t.Fatal("timeout waiting for thread to exit")
+ case syscall.WAIT_FAILED:
+ t.Fatalf("WaitForSingleObject failed: %v", err)
+ default:
+ t.Fatalf("WaitForSingleObject returns unexpected value %v", s)
+ }
+
+ var ec uint32
+ r, _, err = d.Proc("GetExitCodeThread").Call(uintptr(h),
uintptr(unsafe.Pointer(&ec)))
+ if r == 0 {
+ t.Fatalf("GetExitCodeThread failed: %v", err)
+ }
+ if ec != 123 {
+ t.Fatalf("expected 123, but got %d", ec)
+ }
}
fails with
C:\>u:\test -test.v -test.run=Another
=== RUN TestCallbackInAnotherThread
--- FAIL: TestCallbackInAnotherThread (0.11 seconds)
syscall_windows_test.go:259: timeout waiting for thread to exit
FAIL
hg id is 39c724dd7f25
Alex
PS: for after Go 1.2
This test diff --git a/src/pkg/runtime/syscall_windows_test.go b/src/pkg/runtime/syscall_windows_test.go --- a/src/pkg/runtime/syscall_windows_test.go +++ b/src/pkg/runtime/syscall_windows_test.go @@ -240,5 +240,35 @@ } func TestCallbackInAnotherThread(t *testing.T) { - // TODO: test a function which calls back in another thread: QueueUserAPC() or CreateThread() + d := GetDLL(t, "kernel32.dll") + + f := func(p uintptr) uintptr { + return p + } + r, _, err := d.Proc("CreateThread").Call(0, 0, syscall.NewCallback(f), 123, 0, 0) + if r == 0 { + t.Fatalf("CreateThread failed: %v", err) + } + h := syscall.Handle(r) + defer syscall.CloseHandle(h) + + switch s, err := syscall.WaitForSingleObject(h, 100); s { + case syscall.WAIT_OBJECT_0: + break + case syscall.WAIT_TIMEOUT: + t.Fatal("timeout waiting for thread to exit") + case syscall.WAIT_FAILED: + t.Fatalf("WaitForSingleObject failed: %v", err) + default: + t.Fatalf("WaitForSingleObject returns unexpected value %v", s) + } + + var ec uint32 + r, _, err = d.Proc("GetExitCodeThread").Call(uintptr(h), uintptr(unsafe.Pointer(&ec))) + if r == 0 { + t.Fatalf("GetExitCodeThread failed: %v", err) + } + if ec != 123 { + t.Fatalf("expected 123, but got %d", ec) + } } fails with C:\>u:\test -test.v -test.run=Another === RUN TestCallbackInAnotherThread --- FAIL: TestCallbackInAnotherThread (0.11 seconds) syscall_windows_test.go:259: timeout waiting for thread to exit FAIL hg id is 39c724dd7f25 Alex PS: for after Go 1.2