Win32 internals question: is the kernel assumed to increment the reference count of a HANDLE during overlapped I/O, such that the "correct" time to CloseHandle is after all I/O is _issued_ rather than completed? Or is it not incremented, so the CloseHandle must be deferred?
-
-
Replying to @cmuratori
Are you asking about hEvent? The kernel has to increment the refcount itself if you passed it in, or else it couldn't safely SetEvent at completion. But if you close the handle just after it's issued, you can't wait on completion using that event, right?
1 reply 0 retweets 0 likes -
This Tweet is unavailable.
-
Replying to @cmuratori @_knutaf
If the overlapped IO adds a ref to the hFile, then the CloseHandle() won't close the file handle, it'll wait until the IO is finished. If the overlapped IO doesn't add a ref, then the CloseHandle will force close the file handle, (probably) cancelling the IO in flight.
2 replies 0 retweets 0 likes -
Replying to @cmuratori @_knutaf
I was wondering which one Windows implemented. I will probably just end up testing experimentally and see what the deal is, but it can be hard to know if the behavior differs on different Windows platforms.
1 reply 0 retweets 0 likes -
Replying to @cmuratori
ah, I see (that's really the only interesting interpretation of your question, now that I think about it). I suspect there is an internal ref, but I haven't run into this before.
1 reply 0 retweets 0 likes -
Replying to @_knutaf @cmuratori
It's Friday and I got curious, so I spelunked in the source, and at least on Win8+, it looks like the file handle is ref'd at the start of the I/O and deref'd after the I/O completes (either successfully or failed). Seems safe to CloseHandle right after issuing IO
1 reply 0 retweets 0 likes -
Replying to @_knutaf @cmuratori
which is the only reasonable way to implement that, so thank god we did it that way
1 reply 0 retweets 0 likes
That is pretty awesome. Sometimes the older Win32 API stuff actually is very sane. I just never know which it is going to be :) Thanks for checking it out!
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.