System.SyncObjs.TConditionVariableCS.WaitFor
Delphi
function WaitFor(CriticalSection: TCriticalSection; TimeOut: Cardinal = INFINITE): TWaitResult; overload;
function WaitFor(var CriticalSection: TRTLCriticalSection; TimeOut: Cardinal = INFINITE): TWaitResult; overload;
C++
HIDESBASE System::Types::TWaitResult __fastcall WaitFor(TCriticalSection* CriticalSection, unsigned TimeOut = (unsigned)(0xffffffff))/* overload */;
HIDESBASE System::Types::TWaitResult __fastcall WaitFor(_RTL_CRITICAL_SECTION &CriticalSection, unsigned TimeOut = (unsigned)(0xffffffff))/* overload */;
inline System::Types::TWaitResult __fastcall WaitFor(unsigned Timeout = (unsigned)(0xffffffff)){ return TSynchroObject::WaitFor(Timeout); }
inline System::Types::TWaitResult __fastcall WaitFor(const System::Timespan::TTimeSpan &Timeout){ return TSynchroObject::WaitFor(Timeout); }
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
function | public | System.SyncObjs.pas System.SyncObjs.hpp |
System.SyncObjs | TConditionVariableCS |
Description
Sleeps on the condition variable and releases the given critical section.
Call WaitFor to sleep on the condition variable and to release the critical section specified through the CriticalSection parameter.
The TimeOut parameter sets the time-out interval. When this interval elapses, the critical section 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 has 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 ReleaseAll methods. Also, other threads might manage to 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 is awakened.