WaitForMultipleobjects 最大等待对象限制
2013-12-17 16:55
501 查看
排查bug 搞了一个下午 最后才定位这个函数 一看API 居然是最大等待个数限制
谨以此文 祭奠那些逝去的细胞
The number of object handles in the array pointed to by lpHandles.
The maximum number of object handles is MAXIMUM_WAIT_OBJECTS.
This parameter cannot be zero.
参见WinNT.h
#define MAXIMUM_WAIT_OBJECTS 64 // Maximum number of wait objects
因而当线程数多于64时WaitForMultipleObjects应做如下更改:
int tempNumThreads = numThreads;
int tempMax = 0;
while( tempNumThreads >= MAXIMUM_WAIT_OBJECTS )
{
tempNumThreads -= MAXIMUM_WAIT_OBJECTS;
WaitForMultipleObjects( MAXIMUM_WAIT_OBJECTS, &hThread[ tempMax], TRUE, INFINITE);
tempMax += MAXIMUM_WAIT_OBJECTS;
}
WaitForMultipleObjects( tempNumThreads, &hThread[ tempMax ], TRUE, INFINITE);
谨以此文 祭奠那些逝去的细胞
The number of object handles in the array pointed to by lpHandles.
The maximum number of object handles is MAXIMUM_WAIT_OBJECTS.
This parameter cannot be zero.
参见WinNT.h
#define MAXIMUM_WAIT_OBJECTS 64 // Maximum number of wait objects
因而当线程数多于64时WaitForMultipleObjects应做如下更改:
int tempNumThreads = numThreads;
int tempMax = 0;
while( tempNumThreads >= MAXIMUM_WAIT_OBJECTS )
{
tempNumThreads -= MAXIMUM_WAIT_OBJECTS;
WaitForMultipleObjects( MAXIMUM_WAIT_OBJECTS, &hThread[ tempMax], TRUE, INFINITE);
tempMax += MAXIMUM_WAIT_OBJECTS;
}
WaitForMultipleObjects( tempNumThreads, &hThread[ tempMax ], TRUE, INFINITE);
相关文章推荐
- WaitForMultipleObjects等待多个事件对象
- WaitForMultipleObjects等待超过MAXIMUM_WAIT_OBJECTS个的内核对象
- WaitForMultipleObjects将用于等待多个对象变为有信号状态
- 如何用WaitForMultipleObjects获取所有被同时触发的内核对象
- delphi 中使用WaitForMultipleObjects等待线程执行,再执行后续代码
- delphi 中使用WaitForMultipleObjects等待线程执行,再执行后续代码
- 等待线程退出 MsgWaitForMultipleObjects和WaitForSingleObject
- 探讨WaitForMultipleObjects如何突破64个句柄的限制
- 临界区、互斥对象、WaitForSingleObject、WaitForMultipleObjects
- WaitForMultipleObjects和Event配合使用,限制程序运行一个实例
- 改进的延时函数Delay(使用MsgWaitForMultipleObjects等待消息或超时的到来)
- delphi 中使用WaitForMultipleObjects等待线程执行,再执行后续代码
- 主线程使用WaitForSingleObject和MsgWaitForMultipleObjects等待线程返回值
- 主线程利用MsgWaitForMultipleObjects等待子线程结束时,同时处理子线程发送的窗口消息
- _beginthreadex使用WaitForMultipleObjects等待退出的问题
- WaitforMultipleObjects和事件对象
- 突破WaitForMultipleObject等待限制
- 用ACE的Reactor模式实现网络通讯时,ACE内部用WSAEventSelect函数把网络事件与一个事件对象关联起来,目的是为了后面用WaitForMultipleObjects函数统一处理。
- 主线程里面使用WaitForSingleObject (WaitForMultipleObjects)需要考虑的情况(转)
- MsgWaitForMultipleObjects