RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TConditionVariableHelper.SleepCS Method

Sleeps on the condition variable and releases the given critical section.

Pascal
function SleepCS(var CriticalSection: TRTLCriticalSection; dwMilliseconds: DWORD): Boolean;
C++
__fastcall Boolean SleepCS(TRTLCriticalSection CriticalSection, DWORD dwMilliseconds);

Call SleepCS to sleep on the condition variable and to release the critical section specified through the CriticalSection parameter.  

The dwMilliseconds 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.  

Condition variables might suddenly wake up without making an explicit call to the Wake or to the WakeAll method. Also, other threads might run before the thread that sleeps on the condition variable is awakened. Therefore, make the call to SleepCS 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!