WaitForMultipleObjects()访问被拒绝

时间:2018-06-12 08:26:45

标签: c++ winapi synchronization kernel

我有下面的线程函数,它只是等待两个内核对象发出信号 等待函数始终使用 WAIT_FAILED 返回 error code 5 (access denied) ,我无法说明原因。

unsigned __stdcall func(void * p_this){
    ReceiverThread * ThisObj = (ReceiverThread *)p_this;
    HANDLE ClientsMutex = ClientsInterface::GetClientsMutex();
    HANDLE WaitFor[2];
    WaitFor[0] = ThisObj->PassiveEvent;
    WaitFor[1] = ClientsMutex;
    res = WaitForMultipleObjects(2, WaitFor, TRUE, INFINITE);
    switch (res)
    {
    case WAIT_OBJECT_0: // both signal
        if(!Clients->empty()){
           dosomthing();
           ReleaseMutex(ClientsMutex);
           ResetEvent(WaitFor[0]);
        }
        break;
    case WAIT_ABANDONED_0:
        MessageBox(NULL, "WAIT_ABANDONED", "WAIT ERR", MB_OK);
        break;
    case WAIT_TIMEOUT:
        MessageBox(NULL, "TimeOut !", "WAIT ERR", MB_OK);
        break;
    case WAIT_FAILED:
        MessageBox(NULL, "Function Failure !", to_string(GetLastError()).c_str() , MB_OK);
        break;
    }
}

事件初始化如下:

PassiveEvent = CreateEvent(
    NULL,              
    TRUE, // ResetEvent is required to set the event to non-signal state.   
    FALSE, // non-signaled initial state.             
    NULL
);

互斥初始化如下:

Mutex = CreateMutex(NULL, FALSE, NULL);

我知道它有点不透明,但那是所有的信息,也许我错过了一些清楚的东西,但我不能告诉为什么WaitForMultipleObjects()得到 access denied 。任何想法?

0 个答案:

没有答案