poco库学习笔记(5) Poco::Thread
2012-09-27 18:22
281 查看
#include <Poco/Thread.h>
#include <Poco/Runnable.h>
#include <iostream>
class ReadThread:public Poco::Runnable{
virtual void run(){
for(int i=0;i<10;++i){
std::cout<<"helloworld"<<std::endl;
sleep(1);//睡眠1秒
}
}
};
class WriteThread:public Poco::Runnable{
virtual void run(){
for(int i=0;i<10;++i){
std::cout<<"we are the world"<<std::endl;
sleep(2);//睡眠2秒
}
}
};
int main(int argc,char** argv){
ReadThread read;
WriteThread write;
Poco::Thread readThread;
Poco::Thread writeThread;
readThread.start(read);//启动线程read
writeThread.start(write);//启动线程write
std::string tname1 = readThread.getName();//获得线程read的名字
std::string tname2 = writeThread.getName();//获得线程write的名字
std::cout<<"tname1->"<<tname1<<std::endl;
std::cout<<"tname2->"<<tname2<<std::endl;
readThread.join();//等待线程执行完毕
writeThread.join();//等待线程执行完毕
return 0;
}
PS:初写文章,文笔生涩之处,各位请见谅,若有疑问或者交流的,可加本人YY号:301558660
转载请注明出处:山水间博客,http://blog.csdn.net/linyanwen99/article/details/8026030
#include <Poco/Runnable.h>
#include <iostream>
class ReadThread:public Poco::Runnable{
virtual void run(){
for(int i=0;i<10;++i){
std::cout<<"helloworld"<<std::endl;
sleep(1);//睡眠1秒
}
}
};
class WriteThread:public Poco::Runnable{
virtual void run(){
for(int i=0;i<10;++i){
std::cout<<"we are the world"<<std::endl;
sleep(2);//睡眠2秒
}
}
};
int main(int argc,char** argv){
ReadThread read;
WriteThread write;
Poco::Thread readThread;
Poco::Thread writeThread;
readThread.start(read);//启动线程read
writeThread.start(write);//启动线程write
std::string tname1 = readThread.getName();//获得线程read的名字
std::string tname2 = writeThread.getName();//获得线程write的名字
std::cout<<"tname1->"<<tname1<<std::endl;
std::cout<<"tname2->"<<tname2<<std::endl;
readThread.join();//等待线程执行完毕
writeThread.join();//等待线程执行完毕
return 0;
}
PS:初写文章,文笔生涩之处,各位请见谅,若有疑问或者交流的,可加本人YY号:301558660
转载请注明出处:山水间博客,http://blog.csdn.net/linyanwen99/article/details/8026030
相关文章推荐
- Poco C++ 学习笔记连载:Poco命令行解释
- Java 学习笔记 (5) - 线程 Thread
- CAFFE源码学习笔记之五-internal_thread
- Linux编程学习笔记 -- Thread
- 【RT-Thread学习笔记 3】线程优先级抢占实验
- ROS进二阶学习笔记(4) - ROS and Multithread
- java学习笔记-Thread
- RT-Thread的线程(任务)处理【RT-Thread学习笔记 2】
- IOS学习笔记23—多线程之NSThread、NSOperation、NSInvocationOperation
- RT-Thread 学习笔记(十) --- 开启基于LWIP协议的网络功能
- rt_thread学习笔记(1)---rt_thread启动流程分析
- 【Darwin学习笔记】之TaskThread
- RT-Thread_manual 学习笔记(六)--I/O 设备管理
- IOS学习笔记49--多线程之Thread
- STM32 + RT Thread OS 学习笔记[七]
- python进阶笔记 thread 和 threading模块学习
- RT-Thread 学习笔记(八)---开启基于SPI Flash的elmfat文件系统(下)
- 线程让出实验【RT-Thread学习笔记 4】
- 学习笔记-Thread
- java学习笔记--Thread