为什么
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_VALUEvalue: By coincidence,the valueINVALID_HANDLE_VALUEhappens to be numerically equal to the pseudohandle returned byGetCurrentProcess(). Many kernel functions accept pseudohandles,so if if you mess up and accidentally call,say,WaitForSingleObjecton a FailedINVALID_HANDLE_VALUEhandle,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.