本文整理汇总了C++中Task::Run方法的典型用法代码示例。如果您正苦于以下问题:C++ Task::Run方法的具体用法?C++ Task::Run怎么用?C++ Task::Run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Task
的用法示例。
在下文中一共展示了Task::Run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AppInit
void AppInit(void) {
TouchPanelTask.Run();
GUITask.Run();
BlinkTask.Run();
printf("Gib was ein:\r\n");
Serial.ReadLn(buf, 10);
printf("Du hast eingegeben: %s", buf);
}
示例2: worker
/**
* @brief ThreadPool::worker - get next task from queue and run it.
*/
void ThreadPool::worker()
{
Task* task = nullptr;
while (m_needStop == false)
{
while (empty())
{
unique_lock<mutex> lock(m_mutex);
m_condVar.wait_for(lock, chrono::seconds(60));
if (m_needStop)
{
unique_lock<mutex> lockPrint(m_mutexPrint);
cout << "Thread #" << this_thread::get_id() << " has finished work" << endl;
return;
}
}
task = getTask();
if (task != nullptr)
{
{
unique_lock<mutex> lockPrint(m_mutexPrint);
cout << "[" << this_thread::get_id() << "] " << "Task priority: " << task->getPriority() << " Task result: ";
}
task->Run();
}
this_thread::yield();
this_thread::sleep_for(chrono::milliseconds(genRand()));
}
}
示例3: ThreadFunction
static void ThreadFunction(ThreadFunctionArg input){
Thread::Thread_Impl &thimble = input.first;
// Call monitor.NotifyAll() until stated equals true to ensure the thread has started.
thimble.monitor.UnboundWait();
input.second = true;
Task *task;
while(thimble.live){
if(thimble.queue.try_pop(task)){
task->Run();
if(task->repeating)
thimble.queue.push(task);
else
delete task;
}
thimble.monitor.UnboundWait();
}
}
示例4: _ThreadProc
void* LinuxThread::_ThreadProc(void* ptrVoid) {
LinuxThread* ptrThis = (LinuxThread*)ptrVoid;
LinuxThreadPool* pool;
Task* task;
pool = dynamic_cast<LinuxThreadPool*>(ptrThis->GetThreadPool());
if (pool == NULL)
return (void*)ER;
while (1) {
if(ptrThis->_shouldTerminate())
break;
task = pool->GetTask();
if (task) {
task->Run();
delete task;
task = NULL;
}
else {
ptrThis->_suspend();
}
}
return (void*)OK;
}
示例5: WaitForTaskFinished
void TaskScheduler::WaitForTaskFinished(TaskId const & parTaskId)
{
while (IsTaskFinished(parTaskId))
{
// don't waste my time, maybe I can work with you my friends
Task * task = nullptr;
if (_useThisThreadDuringWait)
{
std::lock_guard<std::mutex> ul(this->_taskListMutex);
task = PickupTaskIFP();
}
if (task)
{
task->Run();
ReleaseTask(task);
task = nullptr;
}
else
{
std::unique_lock<std::mutex> ul(this->_taskListMutex);
this->_oneTaskRelease.wait(ul);
}
}
}
示例6: ThreadLoop
void Scheduler::ThreadLoop()
{
for(;;)
{
Task todo;
{
std::unique_lock<std::mutex> lock(mutex);
if (!go_on) // must test it while locked
break;
if (tasks.empty())
{
blocker.wait(lock);
continue;
}
if (tasks.begin()->first <= std::chrono::system_clock::now())
{
todo = tasks.begin()->second;
tasks.erase(tasks.begin());
}
else
{
blocker.wait_until(lock, tasks.begin()->first);
continue;
}
}
// Run task while unlocked so it can schedule new tasks
todo.Run();
}
}
示例7: RepetitiveTask
void RepetitiveTask(Task::TaskData & parTask)
{
TaskScheduler * scheduler = parTask.RepetetiveTaskData.Scheduler;
TaskId taskToExec = parTask.RepetetiveTaskData.RepetiveTask;
std::chrono::milliseconds repeatTimer = parTask.RepetetiveTaskData.RepeatTimer;
Task * task = scheduler->GetTask(taskToExec);
assert(task != nullptr);
task->Run();
scheduler->ScheduleEvery(repeatTimer, taskToExec, false);
}
示例8: RenderWorkThread
unsigned int __stdcall RenderWorkThread(LPVOID param)
{
RenderThreadParam *p = (RenderThreadParam *) param;
Task *task = NULL;
while ( true ) {
task = gEngine.taskManager.ExtractTask();
if ( !task ) break;
task->Run();
delete task;
}
return 0;
}
示例9: PerformTask
void Thread::PerformTask(TaskGroup *pool){
while(true){
Task * task;
if(!pool->queue.try_pop(task))
break;
task->Run();
if(task->repeating)
pool->queue.push(task);
else
delete task;
}
}
示例10: 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
}
示例11: WorkerFunction
void Farm::WorkerFunction()
{
while (true)
{
queueLock_.lock();
Task *t = NULL;
if (!tasks_.empty())
{
t = tasks_.front();
tasks_.pop();
}
queueLock_.unlock();
if (t == NULL)
{
break;
}
else
{
t->Run();
}
}
//another suggestion psudeoish code
//Task *t = nullptr;
//do {
// {
// lock_guard<mutex> lock(queueLock);
// if (!queue.empty())
// t = queue.pop();
// }
// if (t != nullptr)
// t->run();
//} while (t != nullptr);
}
示例12: Loop
void Worker::Loop()
{
if (terminate_requested_)
{
return;
}
Task* t = queue_->GetNext();
if (!t)
{
//printf("%08x: no task\n", ::GetCurrentThreadId());
::SleepEx(1, TRUE);
return;
}
t->Run();
SleepEx(0, TRUE); // handle completion routines
}
示例13: Run
inline void TaskThread::Run(void* arg)
{
idleStart = time(NULL);
do
{
currentTask = queue.Pop();
if (currentTask != NULL)
{
currentTask->Run();
currentTask = NULL;
idleStart = time(NULL);
}
else
{
Sleep(1);
}
}
while (!GetStop());
}
示例14: Thread
unsigned __stdcall TaskQueue::Thread(void *argList) {
DWORD threadID = GetCurrentThreadId();
Task * task;
TaskQueue * taskQueue = (TaskQueue *)argList;
while(1)
{
taskQueue->logger->Log(LOG_DEFAULT, L"Thread[%d] Before GetTask().\n", threadID);
task = taskQueue->GetTask();
taskQueue->logger->Log(LOG_DEFAULT, L"Thread[%d] After GetTask().\n", threadID);
if (task)
{
task->Run();
taskQueue->logger->Log(LOG_DEFAULT, L"Thread[%d] Task complete.\n", threadID);
}
else
break;
}
taskQueue->logger->Log(LOG_DEFAULT, L"Thread[%d] Before exit.\n", threadID);
return 0;
}
示例15: Run
void Run(Task<void()>& task)
{
m_voidGroup.push_back(task.Run());
}