Was macht WaitForSingleObject?

Hi,

kann mir bitte mal jemand erklären, was die Funktion WaitForSingleObject genau macht? Ich denke, sie wartet darauf, dass ein Thread terminiert (wenn Variable „infinite“), und gibt dann einen Wert zurück. Oder seh ich das falsch?

mfg
Philipp

kann mir bitte mal jemand erklären, was die Funktion
WaitForSingleObject genau macht? Ich denke, sie wartet darauf,
dass ein Thread terminiert (wenn Variable „infinite“), und
gibt dann einen Wert zurück. […]

Die WaitForSingleObject wartet darauf, dass eines der folgenden Ereignisse eintritt:

a) Das angebene Handle/Objekt ist im Zustand „signaled“
Bei einem Thread-Handle heißt das: es ist terminiert,
bei einem Event-Handle: Es ist im Zustand „aktiv“ z.B. durch SetEvent/PulseEvent.

b) Das Zeitintervall ist abgelaufen (nur wenn nicht „infinite“)

Auszug aus der Doku:

DWORD WaitForSingleObject(
HANDLE hHandle, // handle to object
DWORD dwMilliseconds // time-out interval
);

The WaitForSingleObject function returns when one of the following occurs:

The specified object is in the signaled state.
The time-out interval elapses.

Parameters
hHandle
[in] Handle to the object. For a list of the object types whose handles can be specified, see the following Remarks section.
If this handle is closed while the wait is still pending, the function’s behavior is undefined.

dwMilliseconds
[in] Specifies the time-out interval, in milliseconds. The function returns if the interval elapses, even if the object’s state is nonsignaled. If dwMilliseconds is zero, the function tests the object’s state and returns immediately. If dwMilliseconds is INFINITE, the function’s time-out interval never elapses.

Return Values
If the function succeeds, the return value indicates the event that caused the function to return. This value can be one of the following.

WAIT_ABANDONED: The specified object is a mutex object that was not released by the thread that owned the mutex object before the owning thread terminated. Ownership of the mutex object is granted to the calling thread, and the mutex is set to nonsignaled.
WAIT_OBJECT_0: The state of the specified object is signaled.
WAIT_TIMEOUT: The time-out interval elapsed, and the object’s state is nonsignaled.

Klaus