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


C++ Task::Run方法代码示例

本文整理汇总了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);
}	
开发者ID:bonzehan,项目名称:stm32-projects,代码行数:9,代码来源:tasks.cpp

示例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()));
    }
}
开发者ID:skident,项目名称:Patterns,代码行数:34,代码来源:threadpool.cpp

示例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();
    }
}
开发者ID:FlyingJester,项目名称:Kashyyyk,代码行数:25,代码来源:background.cpp

示例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;
}
开发者ID:TianLanhe,项目名称:Encrypt,代码行数:25,代码来源:LinuxThread.cpp

示例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);
		}
	}
}
开发者ID:Pamilator,项目名称:TaskScheduler,代码行数:25,代码来源:TaskScheduler.cpp

示例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();
		}
	}
开发者ID:gbizzotto,项目名称:freon,代码行数:30,代码来源:Scheduler.cpp

示例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);
}
开发者ID:Pamilator,项目名称:TaskScheduler,代码行数:11,代码来源:Task.cpp

示例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;
}
开发者ID:zhaoruoxu,项目名称:lyraefx,代码行数:13,代码来源:Parallel.cpp

示例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;
    }
}
开发者ID:FlyingJester,项目名称:Kashyyyk,代码行数:14,代码来源:background.cpp

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

示例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);


}
开发者ID:zecbmo,项目名称:graphicsCW,代码行数:44,代码来源:Farm.cpp

示例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
}
开发者ID:cfo82,项目名称:asyncpp,代码行数:19,代码来源:worker.cpp

示例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());
}
开发者ID:meteor1113,项目名称:library,代码行数:19,代码来源:threadpool.hpp

示例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;
}
开发者ID:PaulJing,项目名称:Sora,代码行数:24,代码来源:TaskQueue.cpp

示例15: Run

		void Run(Task<void()>& task)
		{
			m_voidGroup.push_back(task.Run());
		}
开发者ID:SiChiTong,项目名称:TaskCppV1.1,代码行数:4,代码来源:TaskGroup.hpp


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