RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TConditionVariableMutex.WaitFor Method

Sleeps on the condition variable and releases the specified mutex.

Pascal
function WaitFor(AExternalMutex: TMutex; TimeOut: LongWord = INFINITE): TWaitResult;
C++
__fastcall TWaitResult WaitFor(TMutex AExternalMutex, LongWord TimeOut = INFINITE);

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. 

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!