Export (0) Print
Expand All
Expand Minimize

SleepConditionVariableCS function

Sleeps on the specified condition variable and releases the specified critical section as an atomic operation.

Syntax


BOOL WINAPI SleepConditionVariableCS(
  _Inout_  PCONDITION_VARIABLE ConditionVariable,
  _Inout_  PCRITICAL_SECTION CriticalSection,
  _In_     DWORD dwMilliseconds
);

Parameters

ConditionVariable [in, out]

A pointer to the condition variable. This variable must be initialized using the InitializeConditionVariable function.

CriticalSection [in, out]

A pointer to the critical section object. This critical section must be entered exactly once by the caller at the time SleepConditionVariableCS is called.

dwMilliseconds [in]

The time-out interval, in milliseconds. If the time-out interval elapses, the function re-acquires the critical section and returns zero. If dwMilliseconds is zero, the function tests the states of the specified objects and returns immediately. If dwMilliseconds is INFINITE, the function's time-out interval never elapses. For more information, see Remarks.

Return value

If the function succeeds, the return value is nonzero.

If the function fails or the time-out interval elapses, the return value is zero. To get extended error information, call GetLastError. Possible error codes include ERROR_TIMEOUT, which indicates that the time-out interval has elapsed before another thread has attempted to wake the sleeping thread.

Remarks

A thread that is sleeping on a condition variable can be woken before the specified time-out interval has elapsed using the WakeConditionVariable or WakeAllConditionVariable function. In this case, the thread wakes when the wake processing is complete, and not when its time-out interval elapses. After the thread is woken, it re-acquires the critical section it released when the thread entered the sleeping state.

Condition variables are subject to spurious wakeups (those not associated with an explicit wake) and stolen wakeups (another thread manages to run before the woken thread). Therefore, you should recheck a predicate (typically in a while loop) after a sleep operation returns.

Windows Phone 8: This API is supported.

Windows Phone 8.1: This API is supported.

Examples

For an example that uses this function, see Using Condition Variables.

Requirements

Minimum supported client

Windows Vista [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2008 [desktop apps | Windows Store apps]

Header

WinBase.h on Windows Vista, Windows 7, Windows Server 2008, and Windows Server 2008 R2 (include Windows.h);
Synchapi.h on Windows 8 and Windows Server 2012

Library

Kernel32.lib

DLL

Kernel32.dll

See also

Condition Variables
Synchronization Functions

 

 

Community Additions

ADD
Show:
© 2014 Microsoft