加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 为什么WaitForSingleObject(INVALID_HANDLE_VALUE,IN

发布时间:2020-12-14 04:11:07 所属栏目:Windows 来源:网络整理
导读:为什么 HANDLE mutexHandle = INVALID_HANDLE_VALUE;WaitForSingleObject(mutexHandle,INFINITE); 块?它不会返回错误消息.检查INVALID_HANDLE的句柄对于互斥锁来说是愚蠢的,因为我需要一个互斥锁来访问互斥锁句柄… BTW:如果句柄关闭,它确实返回WAIT_FAILE
为什么
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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读