积极答复者
多线程 WaitForMultipleObject 优先级的问题

问题
-
哪位知道,一个线程等待多个object 是不是有优先级高低的问题。举个例子如下:
============ BEGIN CODE =========================
HANDLE handlesToWaitFor[3];
handlesToWaitFor[0] = evtA;
handlesToWaitFor[1] = evtB;
handlesToWaitFor[2] = evtC;while (!Kill)
{
dwHandleSignaled = WaitForMultipleObjects(15,handlesToWaitFor,FALSE,INFINITE);switch(dwHandleSignaled)
{
case WAIT_OBJECT_0: ... // evtA comes
case WAIT_OBJECT_0 + 1: ... // evtB comes
case WAIT_OBJECT_0 + 2:... // evtC comes
}
}============= END CODE =======================
问题是,如果evtA和evtB同时有很多,这样线程会先把所有的 evtA执行完,然后
再去执行evtB,因为evtA 在evtB前面(这是我观察的结论,虽然是case语法,但仍然有
优先级别)
Questions :
(1) 请问有人遇到这情况吗?是不是确实有evt优先级问题
(2)如果要改成所有evt平等没有优先级,改怎么做?
thanks
答案
全部回复
-
When bWaitAll is FALSE, this function checks the handles in the array in order starting with index 0, until one of the objects is signaled. If multiple objects become signaled, the function returns the index of the first handle in the array whose object was signaled.
以上是MSDN的描述。那么被激活则返回第一个index的事件。所以每次都是前面的Evta被触发。
麻烦把正确答案设为解答。