本文整理汇总了C++中ConditionVariable::Signal方法的典型用法代码示例。如果您正苦于以下问题:C++ ConditionVariable::Signal方法的具体用法?C++ ConditionVariable::Signal怎么用?C++ ConditionVariable::Signal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConditionVariable
的用法示例。
在下文中一共展示了ConditionVariable::Signal方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ConsumerThread
void ConsumerThread(int id)
{
LOG("Starting consumer thread " << id);
for(;;)
{
{
Mutex::Lock __(ItemBufferLock);
while(QueueSize == 0 && !StopRequested)
ItemBufferNotEmpty.Wait(ItemBufferLock);
if(StopRequested && QueueSize == 0)
break;
int Item = ItemBuffer[QueueStartOffset];
QueueSize--;
QueueStartOffset++;
TotalItemsConsumed++;
if(QueueStartOffset == BUFFER_SIZE)
QueueStartOffset = 0;
LOG("Consumer " << id << ", item " << Item << ", queue size " << QueueSize);
}
ItemBufferNotFull.Signal();
Sleep(Random(CONSUMER_SLEEP_TIME_MS));
}
LOG("Consumer exiting");
}
示例2: ProducerThread
void ProducerThread()
{
LOG("Starting producer thread");
for(;;) {
Sleep(Random(PRODUCER_SLEEP_TIME_MS));
{
Mutex::Lock __(ItemBufferLock);
while(QueueSize == BUFFER_SIZE && !StopRequested)
ItemBufferNotFull.Wait(ItemBufferLock);
if(StopRequested)
break;
int Item = Random(1000);
ItemBuffer[(QueueStartOffset + QueueSize) % BUFFER_SIZE] = Item;
QueueSize++;
TotalItemsProduced++;
LOG("Producer item " << Item << ", queue size " << QueueSize);
}
ItemBufferNotEmpty.Signal();
}
LOG("Producer exiting");
}
示例3: WaitForAllTasks
static DWORD WINAPI taskEntry(LPVOID arg) {
#else
static void *taskEntry(void *arg) {
#endif
while (true) {
workerSemaphore.Wait();
// Try to get task from task queue
Task *myTask = NULL;
{ MutexLock lock(*taskQueueMutex);
if (taskQueue.size() == 0)
break;
myTask = taskQueue.back();
taskQueue.pop_back();
}
// Do work for _myTask_
PBRT_STARTED_TASK(myTask);
myTask->Run();
PBRT_FINISHED_TASK(myTask);
tasksRunningCondition.Lock();
int unfinished = --numUnfinishedTasks;
if (unfinished == 0)
tasksRunningCondition.Signal();
tasksRunningCondition.Unlock();
}
// Cleanup from task thread and exit
#ifdef PBRT_HAS_PTHREADS
pthread_exit(NULL);
#endif // PBRT_HAS_PTHREADS
return 0;
}
#endif // !PBRT_USE_GRAND_CENTRAL_DISPATCH
void WaitForAllTasks() {
#ifdef PBRT_USE_GRAND_CENTRAL_DISPATCH
dispatch_group_wait(gcdGroup, DISPATCH_TIME_FOREVER);
#else
tasksRunningCondition.Lock();
while (numUnfinishedTasks > 0)
tasksRunningCondition.Wait();
tasksRunningCondition.Unlock();
#endif
}
示例4: assert
int
WinMonitorData::SignalCondition( unsigned int cvid )
{
int ret = -1;
assert( hMutex != NULL );
ConditionVariableMap::iterator iter = cvmap.find( cvid );
if( iter != cvmap.end() )
{
ConditionVariable* cv = cvmap[cvid];
assert( cv != NULL );
ret = cv->Signal();
}
else
{
// bad cvid
// TODO how to indicate the error?
}
return ret;
}
示例5: MarkAsStarted
void OlaServerThread::MarkAsStarted() {
m_mutex.Lock();
m_is_running = true;
m_mutex.Unlock();
m_condition.Signal();
}