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

相关文章

C++统计函数执行时间的最佳实践

《C++统计函数执行时间的最佳实践》在软件开发过程中,性能分析是优化程序的重要环节,了解函数的执行时间分布对于识别性能瓶颈至关重要,本文将分享一个C++函数执行时间统计工具,希望对大家有所帮助... 目录前言工具特性核心设计1. 数据结构设计2. 单例模式管理器3. RAII自动计时使用方法基本用法高级用法

GO语言中函数命名返回值的使用

《GO语言中函数命名返回值的使用》在Go语言中,函数可以为其返回值指定名称,这被称为命名返回值或命名返回参数,这种特性可以使代码更清晰,特别是在返回多个值时,感兴趣的可以了解一下... 目录基本语法函数命名返回特点代码示例命名特点基本语法func functionName(parameters) (nam

Python Counter 函数使用案例

《PythonCounter函数使用案例》Counter是collections模块中的一个类,专门用于对可迭代对象中的元素进行计数,接下来通过本文给大家介绍PythonCounter函数使用案例... 目录一、Counter函数概述二、基本使用案例(一)列表元素计数(二)字符串字符计数(三)元组计数三、C

Python中的filter() 函数的工作原理及应用技巧

《Python中的filter()函数的工作原理及应用技巧》Python的filter()函数用于筛选序列元素,返回迭代器,适合函数式编程,相比列表推导式,内存更优,尤其适用于大数据集,结合lamb... 目录前言一、基本概念基本语法二、使用方式1. 使用 lambda 函数2. 使用普通函数3. 使用 N

MySQL中REPLACE函数与语句举例详解

《MySQL中REPLACE函数与语句举例详解》在MySQL中REPLACE函数是一个用于处理字符串的强大工具,它的主要功能是替换字符串中的某些子字符串,:本文主要介绍MySQL中REPLACE函... 目录一、REPLACE()函数语法:参数说明:功能说明:示例:二、REPLACE INTO语句语法:参数

python中update()函数的用法和一些例子

《python中update()函数的用法和一些例子》update()方法是字典对象的方法,用于将一个字典中的键值对更新到另一个字典中,:本文主要介绍python中update()函数的用法和一些... 目录前言用法注意事项示例示例 1: 使用另一个字典来更新示例 2: 使用可迭代对象来更新示例 3: 使用

Python lambda函数(匿名函数)、参数类型与递归全解析

《Pythonlambda函数(匿名函数)、参数类型与递归全解析》本文详解Python中lambda匿名函数、灵活参数类型和递归函数三大进阶特性,分别介绍其定义、应用场景及注意事项,助力编写简洁高效... 目录一、lambda 匿名函数:简洁的单行函数1. lambda 的定义与基本用法2. lambda

Python 函数详解:从基础语法到高级使用技巧

《Python函数详解:从基础语法到高级使用技巧》本文基于实例代码,全面讲解Python函数的定义、参数传递、变量作用域及类型标注等知识点,帮助初学者快速掌握函数的使用技巧,感兴趣的朋友跟随小编一起... 目录一、函数的基本概念与作用二、函数的定义与调用1. 无参函数2. 带参函数3. 带返回值的函数4.

MySQL中DATE_FORMAT时间函数的使用小结

《MySQL中DATE_FORMAT时间函数的使用小结》本文主要介绍了MySQL中DATE_FORMAT时间函数的使用小结,用于格式化日期/时间字段,可提取年月、统计月份数据、精确到天,对大家的学习或... 目录前言DATE_FORMAT时间函数总结前言mysql可以使用DATE_FORMAT获取日期字段

Django中的函数视图和类视图以及路由的定义方式

《Django中的函数视图和类视图以及路由的定义方式》Django视图分函数视图和类视图,前者用函数处理请求,后者继承View类定义方法,路由使用path()、re_path()或url(),通过in... 目录函数视图类视图路由总路由函数视图的路由类视图定义路由总结Django允许接收的请求方法http