如果我有下面的C++代碼(Windows版):WaitForMultipleObjects的一個互斥和事件
HANDLE hEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
HANDLE hMutex = ::CreateMutex(NULL, FALSE, NULL);
HANDLE hHandles[] = {
hEvent,
hMutex
};
DWORD dwR = ::WaitForMultipleObjects(2, hHandles, FALSE, INFINITE) - WAIT_OBJECT_0;
//if dwR == 0, what state is hMutex in?
//Or, do I need to call ReleaseMutex(hMutex) in that case?
我不知道如何處理有關互斥這種情況。
謝謝。這就是我需要知道的。順便說一句,在談到WAIT_OBJECT_0時,我在檢查之前減去了它。 – c00000fd
哦,是的,你做了 - 對不起,我錯過了那部分。 –
不要像你一樣無條件地減去它。 'WaitForMultipleObject()'可以返回不應該使用'WAIT_OBJECT_0'的其他錯誤代碼。只有在WaitForMultipleObjects()返回WAIT_OBJECT_0 + 0或WAIT_OBJECT_0 + 1時,才減去它。 –