DWORD WaitForMultipleObjects(DWORD count, const HANDLE* pHandles, DWORD millisecs)
{
DWORD retval = WAIT_TIMEOUT;
// Check if objects need to be split up. In theory, the maximum is
// MAXIMUM_WAIT_OBJECTS, but I found this code performs slightly faster
// if the object are broken down in batches smaller than this.
if (count > 25)
{
// loop continuously if infinite timeout specified
do
{
// divide the batch of handles in two halves ...
DWORD split = count / 2;
DWORD wait = (millisecs == INFINITE ? 2000 : millisecs) / 2;
int random = rand();
// ... and recurse down both branches in pseudo random order
for (short branch = 0; branch < 2 && retval == WAIT_TIMEOUT; branch++)
{
if (random % 2 == branch)
{
// recurse the lower half
retval = testWindows::WaitForMultipleObjects(split, pHandles, wait);
}
else
{
// recurse the upper half
retval
WaitForMultipleObjects 超过 64个handle
最新推荐文章于 2020-11-24 22:41:41 发布