WaitForSingleObject on a file handle?

后端 未结 2 418
無奈伤痛
無奈伤痛 2020-12-17 15:01

What happens when you call WaitForSingleObject() on a handle you\'ve created with CreateFile() or _get_osfhandle()?

For reason

2条回答
  •  萌比男神i
    2020-12-17 15:07

    Don't do it. As you can see, it has undefined behavior.

    Even when the behavior is defined, it's defined in such a way as to be relatively not useful unless you don't like writing additional code. It is signaled when any asynchronous I/O operation on that handle completes, which does not generalize to tracking which I/O operation finished.

    Why are you trying to wait on a file handle? Clearly the intent matters when you are doing something that isn't even supported well enough to not block indefinitely.

提交回复
热议问题