template<class T>
class CotCHelpers::CProtectedVariable< T >
Represents a locked variable. It is used when a content has to be accessed mutually exclusively on multiple threads, and you want one of the threads to wait for a modification.
CProtectedVariable<int> countGuard(0);
void takeOneAndWaitUntilAvailable() {
int *count = countGuard.LockVar();
while (*count == 0) {
countGuard.Wait();
}
(*count) -= 1;
count = countGuard.UnlockVar();
}
void giveOne() {
int *count = countGuard.LockVar();
if (*count == 0) {
countGuard.SignalAll();
}
(*count) += 1;
count = countGuard.UnlockVar();
}