windows – 为什么WaitForSingleObject(INVALID_HANDLE_VALUE,INFINITE)会阻塞?

前端之家收集整理的这篇文章主要介绍了windows – 为什么WaitForSingleObject(INVALID_HANDLE_VALUE,INFINITE)会阻塞?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
为什么
HANDLE mutexHandle = INVALID_HANDLE_VALUE;
WaitForSingleObject(mutexHandle,INFINITE);

块?它不会返回错误消息.检查INVALID_HANDLE的句柄对于互斥锁来说是愚蠢的,因为我需要一个互斥锁来访问互斥锁句柄…

BTW:如果句柄关闭,它确实返回WAIT_Failed.

http://blogs.msdn.com/oldnewthing/archive/2004/03/02/82639.aspx开始:

Fourth,you have to be particularly careful with the INVALID_HANDLE_VALUE value: By coincidence,the value INVALID_HANDLE_VALUE happens to be numerically equal to the pseudohandle returned by GetCurrentProcess(). Many kernel functions accept pseudohandles,so if if you mess up and accidentally call,say,WaitForSingleObject on a Failed INVALID_HANDLE_VALUE handle,you will actually end up waiting on your own process. This wait will,of course,never complete,because a process is signalled when it exits,so you ended up waiting for yourself.

原文链接:https://www.f2er.com/windows/364800.html

猜你在找的Windows相关文章