Poco 线程、任务实现: Poco Task 、Poco Thread
2013-03-28 13:47
369 查看
#include <iostream> #include <stdio.h> #include <Poco/Util/TimerTask.h> #include <Poco/Util/Timer.h> #include <Poco/Task.h> #include <Poco/Timestamp.h> #include <Poco/Runnable.h> #include <Poco/Thread.h> using namespace std; //Poco Pthread class TestPthread:public Poco::Runnable { public: void run(); }; void TestPthread::run() { while(1) { cout<<"TestPthread::run test"<<endl; Poco::Thread::sleep(1000); } } //Poco Task class TestTask:public Poco::Task { public: TestTask(std::string str):Task(str){} void runTask(); }; void TestTask::runTask() { while(!isCancelled()) { cout<<"TestTask::run test"<<endl; Poco::Thread::sleep(1000); } } int main() { Poco::Thread pid; /*test Pthread*/ //TestPthread obj; //pid.start(obj); /*test Task*/ TestTask taskobj("123"); pid.start(taskobj); Sleep(3000); taskobj.cancel(); getchar(); return 0; }
相关文章推荐
- Thread线程使用等待唤醒机制实现线程交替执行任务
- thread与runnable实现线程的区别
- ThreadPoolExecutor的应用和实现分析(中)—— 任务处理相关源码分析 线程利用(转)
- JAVA 并发编程随笔【五】Thread线程创建及运行线程任务
- JAVA 并发编程随笔【五】Thread线程创建及运行线程任务
- 使用Thread+Handler实现非UI线程更新UI界面
- java两种启动线程方法根本不同,Thread继承和实现Runable接口
- Android异步处理一:使用Thread+Handler实现非UI线程更新UI界面
- Android多线程任务优化2:实现后台预读线程 .
- RT-Thread的线程(任务)处理
- Android异步处理一:使用Thread+Handler实现非UI线程更新UI界面
- 线程实现Runnable接口比继承Thread的优势
- 用c实现“基于线程的多任务系统的实现”
- Android异步处理一:使用Thread+Handler实现非UI线程更新UI界面
- Android中使用Thread线程与AsyncTask异步任务的区别
- TMsgThread, TCommThread -- 在delphi线程中实现消息循环(105篇博客,好多研究消息的文章)
- JavaSE 学习参考:Runnable接口实现线程任务
- (转).NET 4.5中使用Task.Run和Parallel.For()实现的C# Winform多线程任务及跨线程更新UI控件综合实例
- 线程创建和启动:继承Thread类和实现Runnable接口