On Tue Oct 14 07:51:59 2025 +0000, Zhiyi Zhang wrote:
Both have the same value. What's the difference? INVALID_HANDLE_VALUE has the advantage of being clearly not a valid object.
Well, if `INVALID_HANDLE_VALUE` was an invalid object, wouldn't the tests fail with ERROR_INVALID_HANDLE just like it did for any other invalid objects? Clearly those didn't; the wait just hangs indefinitely. It's because `(HANDLE)-1` actually represents a *valid* object[^1], namely the current process. Process stay unsignaled until termination, which never "happens" for the current process object, making them apt for "never signaled" object in tests.
Note that there are existing usage of `GetCurrentProcess()` for waiting "indefinitely" in dlls/kernel32/tests/sync.c. I couldn't find similar precedents of `INVALID_HANDLE_VALUE` in the same file.
[^1]: IIRC (HANDLE)-1 was actually an invalid handle in old Windows API. It's unfortunate NT chose the same value for the special (current process) handle; note that NT APIs (which exist below kernel32) use NULL for invalid handle value instead.