What happens when you call WaitForSingleObject()
on a handle you've created with CreateFile()
or _get_osfhandle()
?
For reasons not worth explaining I would like to use WaitForSingleObject()
to wait on a HANDLE that I've created with _get_osfhandle(fd)
, where fd
comes from a regular call to _open()
. Is this possible?
I have tried it in practice, and on some machines it works as expected (the HANDLE is always in the signaled state because you can read more data from it), and on some machines WaitForSingleObject()
will block indefinitely if you let it.
The MSDN page for WaitForSingleObject()
says that the only supported things that it handles are "change notifications, console input, events, memory resource notifications, mutex, processes, semaphores, threads, and waitable timers."
Additionally, would it be different if I used CreateFile()
instead of _get_osfhandle()
on a CRT file descriptor?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…