Search

'F'에 해당되는 글 1건

  1. 2017.04.19 WaitForMultipleObjects

WaitForMultipleObjects

Programming/C,CPP,CS 2017. 4. 19. 09:39 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

WaitForMultipleObjects function


WaitForMultipleObjects는 뜻 그대로 여러개의 object handle이 지정된 상태나 일정 시간이 지날때까지 기다리는 함수이다. 예를들면 복수개의 thread가 모두 종료되기를 기다릴 때 사용할 수 있다. 사용방법은 다음과 같다.



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



  - nCount : lpHandles에 들어있는 object handle의 갯수이다. 최대 MAXIMUM_WAIT_OBJECTS (64개)만을 지정할 수 있다.
  - lpHandles : 함수가 기다릴 object handle의 배열이다. 이 배열은 서로 다른 종류의 obejct의 handle들이 들어갈 수 있다.
  - bWaitAll : TRUE이면 lpHandles의 모든 handle의 signal을 기다리고, TRUE이면 하나라도 signal이 오면 리턴된다. 후자의 경우 리턴값은 signal을 준 object가 된다.
  - dwMilliSeconds : bWaitAll에 의한 조건이 만족되지 않더라도 이 값에 의한 시간이 흐르면 함수는 리턴된다. 0이라면 즉시 리턴되고, INFINITE이면 무한정 기다린다.




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

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. This parameter cannot be zero.

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 thatWAIT_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_0to (WAIT_ABANDONED_0nCount– 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
0x00000102L

The time-out interval elapsed and the conditions specified by the bWaitAll parameter are not satisfied.

WAIT_FAILED
(DWORD)0xFFFFFFFF

The function has failed. To get extended error information, call GetLastError.