Jinoh Kang (@iamahuman) commented about dlls/kernel32/tests/pipe.c:
- SetLastError(0xdeadbeef);
- res = pCancelSynchronousIo(GetCurrentThread());
- ok(!res, "CancelSynchronousIo succeeded unexpectedly\n");
- todo_wine
- ok(GetLastError() == ERROR_NOT_FOUND,
"In CancelSynchronousIo failure, expected ERROR_NOT_FOUND, got %ld\n", GetLastError());
- /* synchronous i/o */
- pipe = CreateNamedPipeA(PIPENAME, PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
1, 1024, 1024, NMPWAIT_USE_DEFAULT_WAIT, NULL);
- ok(pipe != INVALID_HANDLE_VALUE, "CreateNamedPipe failed with %lu\n", GetLastError());
- thread = CreateThread(NULL, 0, synchronousIoThreadMain, pipe, 0, NULL);
- /* wait for thread to start listening */
- Sleep(100);
How about the following race-free approach?
```suggestion:-0+0 /* wait for I/O to start, which transitions the pipe handle from signaled to nonsignaled state. */ while ((wait_status = WaitForSingleObject(pipe, 0)) == WAIT_OBJECT_0) Sleep(1); ok(wait_status == WAIT_TIMEOUT, "WaitForSingleObject returned %lu (error %lu)\n", wait_status, GetLastError()); ```
Ditto for other places.