gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 13:00:11 25 4
gpt4 key购买 nike

为什么

HANDLE mutexHandle = INVALID_HANDLE_VALUE;
WaitForSingleObject(mutexHandle, INFINITE);

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

顺便说一句:如果句柄已关闭,它会返回 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.

关于windows - 为什么 WaitForSingleObject(INVALID_HANDLE_VALUE, INFINITE) 会阻塞?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1471688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com