网站首页  词典首页

请输入您要查询的函数:

 

术语 waitformultipleobjects
释义 WaitForMultipleObjects
语法:
C++
DWORD WINAPI WaitForMultipleObjects(
__in DWORD nCount,
__in const HANDLE *lpHandles,
__in BOOL bWaitAll,
__in DWORD dwMilliseconds
);
WaitForMultipleObjects函数
等待,直到一个或多个指定的所有对象是在信号状态或经过的超时间隔。
要输入一个报警等待状态,请使用WaitForMultipleObjectsEx功能。
参数
nCount [in]
对象句柄数指向lpHandles数组中。对象句柄的最大数量MAXIMUM_WAIT_OBJECTS。
lpHandles [in]
一个对象的句柄数组。对于一个对象的句柄类型可以指定清单,请参阅下面的备注部分。该阵列可以包含处理的不同类型的对象。它不能包含相同的处理多个副本。
如果这些处理一个是封闭,而该等待仍悬而未决,该函数的行为是不确定的。
在处理必须有正确的同步访问。有关更多信息,请参阅标准访问权限。
bWaitAll [in]
如果此参数为TRUE,则函数返回时,在lpHandles数组中的所有物体的国家发出信号。如果为FALSE,函数返回时,任何一个对象状态设置为信号。在后一种情况下,返回值表示的对象的情况引起的函数返回。
dwMilliseconds的 [in]
在超时间隔时间,以毫秒为单位。如果一个非零值指定的函数等待,直到指定的对象是信号或经过的时间间隔。如果dwMilliseconds的是零,该函数不进入等待状态,如果指定的对象没有信号,它总是立即返回。如果dwMilliseconds的是无限的,该函数将返回只有在指定的对象发出信号。
返回值
如果函数成功,返回值表示该事件导致该函数返回。它可以是下列值之一。 (请注意,WAIT_OBJECT_0被定义为0和WAIT_ABANDONED_0是0x00000080L定义。)
返回代码/ valueDescription
WAIT_OBJECT_0到(WAIT_OBJECT_0 + nCount - 1)如果bWaitAll为TRUE,则返回值表明,所有指定对象的状态信号。
如果bWaitAll为FALSE,则返回值减去WAIT_OBJECT_0表示满意的是等待的对象lpHandles数组索引。如果多个对象成为在电话信号,这是与所有的信号对象的最小指标值的信号对象的数组索引。
WAIT_ABANDONED_0至(WAIT_ABANDONED_0 + nCount - 1)如果bWaitAll为TRUE,则返回值表明,所有指定对象的状态信号,至少其中一个对象是一个被遗弃的互斥对象。
如果bWaitAll为FALSE,则返回值减去WAIT_ABANDONED_0表明了一个废弃的互斥对象满意等待lpHandles数组索引。对互斥对象的所有权被授予调用线程,而互斥设置为无信号。
如果一个互斥是保护持久状态的信息,您应该检查它的一致性。
WAIT_TIMEOUT
0x00000102LThe超时时间间隔过去了,由bWaitAll参数指定的条件没有得到满足。
WAIT_FAILED
(DWORD值)0xFFFFFFFFThe函数失败。为了获得更多错误信息,调用GetLastError。
备注
在WaitForMultipleObjects函数确定是否等待标准已得到满足。如果条件没有得到满足,调用线程进入等待,直到标准的条件下等待状态已经达到或超时间隔经过的。
当bWaitAll为TRUE,函数的等待操作完成,只有在所有对象的状态已被设置为信号。该函数不修改,直到所有对象的国家指定对象的状态已被设置为信号。例如,一个互斥信号可以,但没有得到线程,直到其他物体的国家所有权也将信号。与此同时,其他一些线程可能获得互斥体的所有权,从而确定其状态无信号。
当bWaitAll是FALSE,此功能检查,以便在处理与数组的索引0开始,直到一个对象发出信号。如果多个对象成为暗示,该函数返回首先处理的信号,其目的是数组的索引。
函数修改了某些类型的同步对象的状态。改造只对一个或多个对象的信号状态发生所造成的函数返回。例如,一个信号量对象计数减少1。有关详细信息,请参阅个别同步对象文件。
要等待多MAXIMUM_WAIT_OBJECTS处理,使用下列方法之一:
创建一个线程就MAXIMUM_WAIT_OBJECTS等待句柄,然后等待该加上其他线程处理。使用此技术来打破成MAXIMUM_WAIT_OBJECTS组处理。
呼叫等待RegisterWaitForSingleObject每个处理。从线程池等待线程等待登记的对象和分配一个工作线程对象后,信号或超时间隔过期关于MAXIMUM_WAIT_OBJECTS。
在WaitForMultipleObjects函数可以指定处理的,在下面的对象数组lpHandles任何类型:
更改通知
控制台输入
事件
内存资源通知
互斥
工艺
信号量
线
可等待定时器
使用时要小心调用等待函数和代码直接或间接产生的窗口。如果一个线程创建的窗口,它必须处理消息。广播消息发送到系统中的所有窗口。一个线程使用,没有时间等待功能超时间隔可能会导致系统变得陷入僵局。两个代码,间接创造DDE和窗口的CoInitialize函数的例子。因此,如果您有一个线程创建的窗口,使用MsgWaitForMultipleObjects或MsgWaitForMultipleObjectsEx,而不是WaitForMultipleObjects的。
实例
有关示例,请等待多个对象。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
同步功能
等待函数
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==WaitForMultipleObjects Function
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.
Syntax
C++
DWORD WINAPI WaitForMultipleObjects(
__in DWORD nCount,
__in const HANDLE *lpHandles,
__in BOOL bWaitAll,
__in DWORD dwMilliseconds
);
Parameters
nCount [in]
The number of object handles in the array pointed to by lpHandles. The maximum number of object handles is MAXIMUM_WAIT_OBJECTS.
lpHandles [in]
An 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 .
bWaitAll [in]
If 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.
dwMilliseconds [in]
The time-out interval, in milliseconds. If a nonzero value is specified, the function waits until the specified objects are signaled or the interval elapses. If dwMilliseconds is zero, the function does not enter a wait state if the specified objects are not signaled; it always returns immediately. If dwMilliseconds is INFINITE, the function will return only when the specified objects are signaled.
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.)
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.
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.
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.
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.
If a mutex was protecting persistent state information, you should check it for consistency.
WAIT_TIMEOUT
0x00000102LThe time-out interval elapsed and the conditions specified by the bWaitAll parameter are not satisfied.
WAIT_FAILED
(DWORD)0xFFFFFFFFThe function has failed. To get extended error information, call 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.
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.
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.
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.
To wait on more than MAXIMUM_WAIT_OBJECTS handles, use one of the following methods:
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.
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.
The WaitForMultipleObjects function can specify handles of any of the following object types in the lpHandles array:
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.
Examples
For an example, see Waiting for Multiple Objects .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
See Also
Synchronization Functions
Wait Functions
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms687025(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:25:12