当前位置: 首页>>代码示例>>C++>>正文


C++ ConditionVariable::Signal方法代码示例

本文整理汇总了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");
}
开发者ID:AbdelghaniDr,项目名称:mirror,代码行数:31,代码来源:ConditionVariable.cpp

示例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");
}
开发者ID:AbdelghaniDr,项目名称:mirror,代码行数:26,代码来源:ConditionVariable.cpp

示例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
}
开发者ID:joohaeng,项目名称:pbrt-v2,代码行数:44,代码来源:parallel.cpp

示例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;
}
开发者ID:bwelton,项目名称:mrnet,代码行数:22,代码来源:Monitor-win.C

示例5: MarkAsStarted

void OlaServerThread::MarkAsStarted() {
  m_mutex.Lock();
  m_is_running = true;
  m_mutex.Unlock();
  m_condition.Signal();
}
开发者ID:mlba-team,项目名称:open-lighting,代码行数:6,代码来源:StreamingClientTest.cpp


注:本文中的ConditionVariable::Signal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。