Topics |
|
The condition variable class is a synchronization mechanism used by a thread to block its own execution until an expression involving shared data reaches a particular state.
The following enumeration is used define integer constants used with the vbCondition class:
enum vbConditionError { // Condition variables error codes vbCONDITION_NO_ERROR = 0, // No errors reported vbCONDITION_INVALID_CODE, // Invalid error code vbCONDITION_ATTR_DESTROY_ERROR, // Error destroying attribute vbCONDITION_ATTR_INIT_ERROR, // Error initializing the attribute vbCONDITION_BROADCAST_ERROR, // Error broadcasting vbCONDITION_DESTROY_ERROR, // Error destroying condition vbCONDITION_EXTERNAL_ERROR, // External mutex error vbCONDITION_INIT_ERROR, // Error initializing condition vbCONDITION_INTERNAL_ERROR, // Internal condition error vbCONDITION_SET_SHARE_ERROR, // Error setting shared attribute vbCONDITION_SIGNAL_ERROR, // Error signaling vbCONDITION_TIMED_WAIT_ERROR, // Error during a timed waiting vbCONDITION_WAIT_ERROR // Error waiting };
vbCondition::ConditionBroadcast
vbCondition::ConditionDestroy
vbCondition::ConditionExceptionMessage
vbCondition::ConditionInit
vbCondition::ConditionSignal
vbCondition::ConditionTimedWait
vbCondition::ConditionWait
vbCondition::GetCondition
vbCondition::GetConditionError
vbCondition::GetConditionProcessType
vbCondition::NumWaiting
vbCondition::ThreadsWaiting
int vbCondition::ConditionBroadcast()
- Function used to wake up all threads waiting on this condition. Returns a non-zero value if any errors occur.int vbCondition::ConditionDestroy()
- Function used by the vbCondition destructor to destroy the condition variable and free its resources. Returns a non-zero value if the condition variable cannot be destroyed or if any errors occur.const char * vbCondition::ConditionExceptionMessage()
- Returns a null terminated string that can be used to log or print a condition exception.int vbCondition::ConditionInit(vbProcessType type = vbPROCESS_PRIVATE)
- Function used by the vbCondition constructor to initialize the condition variable. By default the process type is set to private meaning that this condition variable can only be shared by threads of the same process. If a vbPROCESS_SHARED process type is specified the condition variable can be shared across multiple processes. Returns a non-zero value if the condition variable cannot be initialized or if any errors occur.int vbCondition::ConditionSignal()
- Function used to wake up a thread waiting on the this condition. Returns a non-zero value if any errors occur.int vbCondition::ConditionTimedWait(vbMutex *m, unsigned long sec, unsigned long nsec=0)
- Function used to block a thread from its own execution until this condition is signaled or the timeout value elapses. Returns a non-zero value if any errors occur.int vbCondition::ConditionWait(vbMutex *m)
- Function used to block a thread from its own execution until this condition is signaled. Returns a non-zero value if any errors occur.vbCondition_t * vbCondition::GetCondition()
- Returns a pointer to the vbCondition_t data structure, which contains platform specific variables. NOTE: This function is provided for debugging and testing purposes only. The vbCondition_t data structure and the helper functions that operate on vbCondition_t types should not be used directly.vbConditionError vbCondition::GetConditionError()
- Returns the last reported condition variable error. The return value will match one of the integer constants defined in vbConditionError enumeration.vbProcessType vbCondition::GetConditionProcessType()
- Returns the process type for this condition. The return value will match one of the integer constants defined in vbProcessType enumeration.int vbCondition::NumWaiting()
- Returns the total number of threads waiting on this condition.int vbCondition::ThreadsWaiting()
- Returns true if any threads are waiting on this condition.The application is responsible for monitoring and handling any condition variable errors that occur following a condition variable operation. An error condition is reported to the application by any condition variable function returning a non-zero value. If any value other then 0 is returned the application must generate the appropriate exception to handle the error condition.
Condition variable errors are recorded by the vbCondition_t helper functions and stored in the vbCondition _t::condition _error variable. The condition variable error variable is accessible to the application though the vbCondition::GetConditionError function. A condition variable error is a numeric value corresponding to one of the integer constants defined in the vbConditionError enumeration. The vbCondition::ConditionExceptionMessage function can be used to log or print a condition variable exception.