#include <p6lock.h>
Inherits P6R::p6ICom.
Public Member Functions | |
virtual P6INT32 | addref (void)=0 |
virtual P6R::P6ERR | initialize (p6ILock *pLock)=0 |
virtual P6R::P6ERR | notify (void)=0 |
virtual P6R::P6ERR | notifyAll (void)=0 |
virtual P6R::P6ERR | queryInterface (const P6R::P6IID &iid, P6VOID **ppIface)=0 |
virtual P6INT32 | release (void)=0 |
virtual P6R::P6ERR | wait (void)=0 |
virtual P6R::P6ERR | waitTimed (P6INTERVAL tTimeout)=0 |
Conditional variable.
To avoid a busy wait, condition variables are used to block threads until a specified condition is true.
Condition variables must always be used with an assosiated lock (P6R::p6ILock). The following code example demonstrates the proper use of a condition variable.
Notice that the wait MUST be called while holding the lock and MUST be called in a while loop testing the condition. This is because on some operating systems, the wait may be terminted prematurely (not the result of a notify() or notify all or the timeout period expiring). This is known as the "spurious wakeup problem" and the while loop works around the issue by ensure that condition was met before continuing.