本文整理汇总了C++中WorkItem::Run方法的典型用法代码示例。如果您正苦于以下问题:C++ WorkItem::Run方法的具体用法?C++ WorkItem::Run怎么用?C++ WorkItem::Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorkItem
的用法示例。
在下文中一共展示了WorkItem::Run方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
void WorkItemQueue::Process()
{
while (!m_dying) {
WorkItem* item = NULL;
boost::unique_lock<boost::mutex> lock(m_mutex);
while ((!m_dying) && (item = Pop())) {
try {
// LslDebug( "running WorkItem %p, prio = %d", item, item->m_priority );
item->Run();
} catch (std::exception& e) {
// better eat all exceptions thrown by WorkItem::Run(),
// don't want to let the thread die on a single faulty WorkItem.
LslDebug("WorkerThread caught exception thrown by WorkItem::Run -- %s", e.what());
} catch (...) {
LslDebug("WorkerThread caught exception thrown by WorkItem::Run");
}
CleanupWorkItem(item);
}
// cleanup leftover WorkItems
while ((item = Pop()) != NULL) {
CleanupWorkItem(item);
}
if (!m_dying)
//wait for the next Push
m_cond.wait(lock);
}
}
示例2: wxLogMessage
void* WorkerThread::Entry()
{
WorkItem* item;
wxLogMessage( _T( "WorkerThread started" ) );
while ( !TestDestroy() ) {
// sleep an hour or until a new WorkItem arrives (DoWork() will wake us up).
Sleep( 3600 * 1000 );
while ( !TestDestroy() && ( item = m_workItems.Pop() ) != NULL ) {
try {
wxLogMessage( _T( "running WorkItem %p, prio = %d" ), item, item->m_priority );
item->Run();
}
catch ( ... ) {
// better eat all exceptions thrown by WorkItem::Run(),
// don't want to let the thread die on a single faulty WorkItem.
wxLogMessage( _T( "WorkerThread caught exception thrown by WorkItem::Run" ) );
}
CleanupWorkItem( item );
// give other threads some air
Yield();
}
}
// cleanup leftover WorkItems
while ( ( item = m_workItems.Pop() ) != NULL ) {
CleanupWorkItem( item );
}
wxLogMessage( _T( "WorkerThread stopped" ) );
return 0;
}