MFC WaitForMultipleObjects 函数

2024-02-09 12:48

本文主要是介绍MFC WaitForMultipleObjects 函数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

WaitForMultipleObjects 函数

  • Syntax
  • Parameters
  • Return Value
  • Remarks

Waits until one or all of the specified objects are in the signaled state or the time-out interval elapses.
【等待,直到一个或所有指定的对象处于信号状态或超时间隔结束。】

To enter an alertable wait state, use the WaitForMultipleObjectsEx function.
【要进入可报警的等待状态,请使用WaitForMultipleObjectsEx函数。】

Syntax

DWORD WINAPI WaitForMultipleObjects(__in  DWORD nCount,__in  const HANDLE* lpHandles,__in  BOOL bWaitAll,__in  DWORD dwMilliseconds
);\

Parameters

nCountThe number of object handles in the array pointed to by lpHandles. The maximum number of object handles is MAXIMUM_WAIT_OBJECTS.
lpHandles指向的数组中的对象句柄数。对象句柄的最大数目是MAXIMUM_WAIT_OBJECTS。
lpHandlesAn array of object handles. For a list of the object types whose handles can be specified, see the following Remarks section. The array can contain handles to objects of different types. It may not contain multiple copies of the same handle.
【对象句柄数组。有关可以指定其句柄的对象类型的列表,请参见下面的备注部分。数组可以包含不同类型对象的句柄。它不能包含同一句柄的多个副本。】
If one of these handles is closed while the wait is still pending, the function’s behavior is undefined.
【如果其中一个句柄在等待仍挂起时关闭,则函数的行为未定义。】
The handles must have the SYNCHRONIZE access right. For more information, see Standard Access Rights.
【句柄必须具有同步访问权限。有关详细信息,请参阅标准访问权限。】
bWaitAllIf this parameter is TRUE, the function returns when the state of all objects in the lpHandles array is signaled. If FALSE, the function returns when the state of any one of the objects is set to signaled. In the latter case, the return value indicates the object whose state caused the function to return.
【如果此参数为TRUE,则当lpHandles数组中所有对象的状态都被通知时,函数返回。如果为FALSE,则当任何一个对象的状态设置为signaled时,函数返回。在后一种情况下,返回值指示其状态导致函数返回的对象。】
dwMillisecondsThe time-out interval, in milliseconds. The function returns if the interval elapses, even if the conditions specified by the bWaitAll parameter are not met. If dwMilliseconds is zero, the function tests the states of the specified objects and returns immediately. If dwMilliseconds is INFINITE, the function’s time-out interval never elapses.
【超时间隔,以毫秒为单位。如果间隔已过,则函数返回,即使bWaitAll参数指定的条件未满足也是如此。如果dwMilliseconds为零,则函数将测试指定对象的状态并立即返回。如果dwMilliseconds是无限的,则函数的超时时间间隔永远不会过去。】

Return Value

If the function succeeds, the return value indicates the event that caused the function to return. It can be one of the following values. (Note that WAIT_OBJECT_0 is defined as 0 and WAIT_ABANDONED_0 is defined as 0x00000080L.)
【如果函数成功,则返回值指示导致函数返回的事件。它可以是以下值之一。(请注意,WAIT_OBJECT_0定义为0,WAIT_ABANDONED_0定义为0x00000080L。)】

Return code/valueDescription
WAIT_OBJECT_0 to (WAIT_OBJECT_0 + nCount– 1)If bWaitAll is TRUE, the return value indicates that the state of all specified objects is signaled.
【如果bWaitAll为TRUE,则返回值指示所有指定对象的状态都被通知。】
If bWaitAll is FALSE, the return value minus WAIT_OBJECT_0 indicates the lpHandles array index of the object that satisfied the wait. If more than one object became signaled during the call, this is the array index of the signaled object with the smallest index value of all the signaled objects.
【如果bWaitAll为FALSE,则返回值减去WAIT_OBJECT_0 表示满足等待的对象的lpHandles数组索引。如果在调用期间有多个对象发出信号,则这是所有发出信号的对象中具有最小索引值的发出信号的对象的数组索引。】
WAIT_ABANDONED_0 to (WAIT_ABANDONED_0 + nCount– 1)If bWaitAll is TRUE, the return value indicates that the state of all specified objects is signaled and at least one of the objects is an abandoned mutex object.
【如果bWaitAll为TRUE,则返回值表示所有指定对象的状态都有信号,并且至少有一个对象是放弃的互斥对象。】
If bWaitAll is FALSE, the return value minus WAIT_ABANDONED_0 indicates the lpHandles array index of an abandoned mutex object that satisfied the wait. Ownership of the mutex object is granted to the calling thread, and the mutex is set to nonsignaled.
【如果bWaitAll为FALSE,则返回值减去WAIT_ABANDONED_0 表示满足等待的废弃互斥对象的lpHandles数组索引。互斥对象的所有权被授予调用线程,互斥被设置为nonsignaled。】
If a mutex was protecting persistent state information, you should check it for consistency.
【如果互斥体正在保护持久状态信息,则应检查其一致性。】
WAIT_TIMEOUT
0x00000102L
The time-out interval elapsed and the conditions specified by the bWaitAll parameter are not satisfied.
【超时间隔已过,bWaitAll参数指定的条件不满足。】

If the function fails, the return value is WAIT_FAILED ((DWORD)0xFFFFFFFF). To get extended error information, call GetLastError.
【如果函数失败,则返回值为WAIT_FAILED ((DWORD)0xFFFFFFFF)。要获取扩展错误信息,请调用GetLastError。】

Remarks

The WaitForMultipleObjects function determines whether the wait criteria have been met. If the criteria have not been met, the calling thread enters the wait state until the conditions of the wait criteria have been met or the time-out interval elapses.
【WaitForMultipleObjects函数确定是否满足等待条件。如果未满足条件,则调用线程将进入等待状态,直到满足等待条件或超时间隔结束。】

When bWaitAll is TRUE, the function’s wait operation is completed only when the states of all objects have been set to signaled. The function does not modify the states of the specified objects until the states of all objects have been set to signaled. For example, a mutex can be signaled, but the thread does not get ownership until the states of the other objects are also set to signaled. In the meantime, some other thread may get ownership of the mutex, thereby setting its state to nonsignaled.
【当bWaitAll为TRUE时,只有当所有对象的状态都设置为signaled时,函数的等待操作才完成。函数不会修改指定对象的状态,直到所有对象的状态都设置为signaled。例如,可以向互斥体发送信号,但是线程在其他对象的状态也设置为signaled之前不会获得所有权。同时,其他线程可能会获得互斥锁的所有权,从而将其状态设置为nonsignaled。】

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.
【当bWaitAll为FALSE时,此函数将按从索引0开始的顺序检查数组中的句柄,直到向其中一个对象被设置为signaled为止。如果多个对象被设置为signaled,函数将返回数组中第一个句柄的索引,该句柄的对象已被设置为signaled。】

The function modifies the state of some types of synchronization objects. Modification occurs only for the object or objects whose signaled state caused the function to return. For example, the count of a semaphore object is decreased by one. For more information, see the documentation for the individual synchronization objects.
【此函数用于修改某些类型的同步对象的状态。仅对其信号状态导致函数返回的一个或多个对象进行修改。例如,信号量对象的计数减少1。有关详细信息,请参阅各个同步对象的文档。】

To wait on more than MAXIMUM_WAIT_OBJECTS handles, use one of the following methods:
【要等待超过MAXIMUM_WAIT_OBJECTS个对象句柄,请使用以下方法之一:】
1.Create a thread to wait on MAXIMUM_WAIT_OBJECTS handles, then wait on that thread plus the other handles. Use this technique to break the handles into groups of MAXIMUM_WAIT_OBJECTS.
【创建一个线程以等待MAXIMUM_WAIT_OBJECTS个对象句柄,然后等待该线程和其他句柄。使用此技术可以将句柄分成MAXIMUM_WAIT_OBJECTS对象组。】
2.Call RegisterWaitForSingleObject to wait on each handle. A wait thread from the thread pool waits on MAXIMUM_WAIT_OBJECTS registered objects and assigns a worker thread after the object is signaled or the time-out interval expires.
【调用RegisterWaitForSingleObject等待每个句柄。线程池中的等待线程等待已注册对象的MAXIMUM_WAIT_OBJECTS个对象,并在对象发出信号或超时间隔过期后分配工作线程。】

The WaitForMultipleObjects function can specify handles of any of the following object types in the lpHandles array:
【WaitForMultipleObjects函数可以在lpHandles数组中指定以下任何对象类型的句柄:】

Change notification 【更改通知】
Console input 【控制台输入】
Event 【事件】
Memory resource notification 【内存资源通知】
Mutex 【互斥】
Process 【进程】
Semaphore 【信号量】
Thread 【线程】
Waitable timer 【等待计时器】
Use caution when calling the wait functions and code that directly or indirectly creates windows. If a thread creates any windows, it must process messages. Message broadcasts are sent to all windows in the system. A thread that uses a wait function with no time-out interval may cause the system to become deadlocked. Two examples of code that indirectly creates windows are DDE and the CoInitialize function. Therefore, if you have a thread that creates windows, use MsgWaitForMultipleObjects or MsgWaitForMultipleObjectsEx, rather than WaitForMultipleObjects.
【在调用直接或间接创建窗口的等待函数和代码时要小心。如果线程创建任何窗口,它必须处理消息。消息广播发送到系统中的所有窗口。使用无超时间隔的等待函数的线程可能会导致系统死锁。间接创建窗口的两个代码示例是DDE和CoInitialize函数。因此,如果有创建窗口的线程,请使用MsgWaitForMultipleObjects或MsgWaitForMultipleObjectsEx,而不是WaitForMultipleObjects。】

这篇关于MFC WaitForMultipleObjects 函数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/694271

相关文章

Kotlin运算符重载函数及作用场景

《Kotlin运算符重载函数及作用场景》在Kotlin里,运算符重载函数允许为自定义类型重新定义现有的运算符(如+-…)行为,从而让自定义类型能像内置类型那样使用运算符,本文给大家介绍Kotlin运算... 目录基本语法作用场景类对象数据类型接口注意事项在 Kotlin 里,运算符重载函数允许为自定义类型重

Pandas中统计汇总可视化函数plot()的使用

《Pandas中统计汇总可视化函数plot()的使用》Pandas提供了许多强大的数据处理和分析功能,其中plot()函数就是其可视化功能的一个重要组成部分,本文主要介绍了Pandas中统计汇总可视化... 目录一、plot()函数简介二、plot()函数的基本用法三、plot()函数的参数详解四、使用pl

Python的time模块一些常用功能(各种与时间相关的函数)

《Python的time模块一些常用功能(各种与时间相关的函数)》Python的time模块提供了各种与时间相关的函数,包括获取当前时间、处理时间间隔、执行时间测量等,:本文主要介绍Python的... 目录1. 获取当前时间2. 时间格式化3. 延时执行4. 时间戳运算5. 计算代码执行时间6. 转换为指

Python正则表达式语法及re模块中的常用函数详解

《Python正则表达式语法及re模块中的常用函数详解》这篇文章主要给大家介绍了关于Python正则表达式语法及re模块中常用函数的相关资料,正则表达式是一种强大的字符串处理工具,可以用于匹配、切分、... 目录概念、作用和步骤语法re模块中的常用函数总结 概念、作用和步骤概念: 本身也是一个字符串,其中

shell编程之函数与数组的使用详解

《shell编程之函数与数组的使用详解》:本文主要介绍shell编程之函数与数组的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录shell函数函数的用法俩个数求和系统资源监控并报警函数函数变量的作用范围函数的参数递归函数shell数组获取数组的长度读取某下的

MySQL高级查询之JOIN、子查询、窗口函数实际案例

《MySQL高级查询之JOIN、子查询、窗口函数实际案例》:本文主要介绍MySQL高级查询之JOIN、子查询、窗口函数实际案例的相关资料,JOIN用于多表关联查询,子查询用于数据筛选和过滤,窗口函... 目录前言1. JOIN(连接查询)1.1 内连接(INNER JOIN)1.2 左连接(LEFT JOI

MySQL中FIND_IN_SET函数与INSTR函数用法解析

《MySQL中FIND_IN_SET函数与INSTR函数用法解析》:本文主要介绍MySQL中FIND_IN_SET函数与INSTR函数用法解析,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友一... 目录一、功能定义与语法1、FIND_IN_SET函数2、INSTR函数二、本质区别对比三、实际场景案例分

C++ Sort函数使用场景分析

《C++Sort函数使用场景分析》sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变,如果某些场景需要保持相同元素间的相对顺序,可使... 目录C++ Sort函数详解一、sort函数调用的两种方式二、sort函数使用场景三、sort函数排序

C语言函数递归实际应用举例详解

《C语言函数递归实际应用举例详解》程序调用自身的编程技巧称为递归,递归做为一种算法在程序设计语言中广泛应用,:本文主要介绍C语言函数递归实际应用举例的相关资料,文中通过代码介绍的非常详细,需要的朋... 目录前言一、递归的概念与思想二、递归的限制条件 三、递归的实际应用举例(一)求 n 的阶乘(二)顺序打印

C/C++错误信息处理的常见方法及函数

《C/C++错误信息处理的常见方法及函数》C/C++是两种广泛使用的编程语言,特别是在系统编程、嵌入式开发以及高性能计算领域,:本文主要介绍C/C++错误信息处理的常见方法及函数,文中通过代码介绍... 目录前言1. errno 和 perror()示例:2. strerror()示例:3. perror(