WaitForSingleObject 返回值为 WAIT_ABANDONED 的情况

WaitForSingleObject函数的原型如下:

DWORD WINAPI WaitForSingleObject(
  __in  HANDLE hHandle,
  __in  DWORD dwMilliseconds
);

关于WAIT_ABANDONED返回值,MSDN的解释如下:

The specified object is a mutex object that was not released by the thread that owned the mutex object before the owning thread terminated. Ownership of the mutex object is granted to the calling thread, and the mutex is set to nonsignaled.

If the mutex was protecting persistent state information, you should check it for consistency.

实际就是下面这中情况:
假设有A、B两个线程和一个互斥量hMutex。如果A线程调用WaitForSingleObject获取到互斥量后,并没有调用ReleaseMutex来释放互斥量就终止了(如调用了ExitThread,TerminateThread)。然后线程B调用WaitForSingleObject就会返回WAIT_ABANDONED,并且线程B获取到互斥量,线程B使用完成后应该调用ReleasMutex释放互斥量。

当返回WAIT_ABANDONED时,应该检查一下互斥量所保护的资源的一致性。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值