System.SyncObjs.TConditionVariableMutex.WaitFor

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function WaitFor(AExternalMutex: TMutex; TimeOut: Cardinal = INFINITE): TWaitResult;

C++

HIDESBASE System::Types::TWaitResult __fastcall WaitFor(TMutex* AExternalMutex, unsigned TimeOut = (unsigned)(0xffffffff));

Properties

Type Visibility Source Unit Parent
function public
System.SyncObjs.pas
System.SyncObjs.hpp
System.SyncObjs TConditionVariableMutex

Description

Sleeps on the condition variable and releases the specified mutex.

Call WaitFor to sleep on the condition variable and to release the mutex specified through the AExternalMutex parameter.

The TimeOut parameter sets the time-out interval. When this interval elapses, the mutex is reacquired, even if the condition variable has not been awakened by other threads.

The result returned by the WaitFor function is of TWaitResult type and can have one of the following values:



Value

Meaning

wrSignaled

The condition variable has been awakened.

wrTimeout

The time-out interval has elapsed without the condition variable being awakened.

wrAbandoned

The condition variable had been destroyed before the time-out interval has elapsed.

wrError

An error occured while waiting. Check the LastError property for an error code giving more information.



Condition variables might suddenly wake up, without making an explicit call to the Release or to the ReleaseAll method. Also, other threads might run before the thread that sleeps on the condition variable is awakened. Therefore, make the call to WaitFor inside a loop. To avoid the above mentioned errors, the loop should test that the desired condition becomes true even after the condition variable has awakened.

See Also