@@ -251,7 +251,39 @@ func TestBlockingCallback(t *testing.T) {
251
251
}
252
252
253
253
func TestCallbackInAnotherThread (t * testing.T ) {
254
- // TODO: test a function which calls back in another thread: QueueUserAPC() or CreateThread()
254
+ t .Skip ("Skipping failing test (see golang.org/issue/6751 for details)" )
255
+
256
+ d := GetDLL (t , "kernel32.dll" )
257
+
258
+ f := func (p uintptr ) uintptr {
259
+ return p
260
+ }
261
+ r , _ , err := d .Proc ("CreateThread" ).Call (0 , 0 , syscall .NewCallback (f ), 123 , 0 , 0 )
262
+ if r == 0 {
263
+ t .Fatalf ("CreateThread failed: %v" , err )
264
+ }
265
+ h := syscall .Handle (r )
266
+ defer syscall .CloseHandle (h )
267
+
268
+ switch s , err := syscall .WaitForSingleObject (h , 100 ); s {
269
+ case syscall .WAIT_OBJECT_0 :
270
+ break
271
+ case syscall .WAIT_TIMEOUT :
272
+ t .Fatal ("timeout waiting for thread to exit" )
273
+ case syscall .WAIT_FAILED :
274
+ t .Fatalf ("WaitForSingleObject failed: %v" , err )
275
+ default :
276
+ t .Fatalf ("WaitForSingleObject returns unexpected value %v" , s )
277
+ }
278
+
279
+ var ec uint32
280
+ r , _ , err = d .Proc ("GetExitCodeThread" ).Call (uintptr (h ), uintptr (unsafe .Pointer (& ec )))
281
+ if r == 0 {
282
+ t .Fatalf ("GetExitCodeThread failed: %v" , err )
283
+ }
284
+ if ec != 123 {
285
+ t .Fatalf ("expected 123, but got %d" , ec )
286
+ }
255
287
}
256
288
257
289
type cbDLLFunc int // int determines number of callback parameters
0 commit comments