昨天刚down了个ZThread,这个库主要用来开发c++的多线程应用。
那么我写的demo是使用windows平台下的dev-c++来做的,如果你用dev-c++,那么首先有1个问题要解决:
http://blog.csdn.net/jimmy_w/archive/2007/12/24/1965313.aspx
这里有解释为什么模板化基类里的名称不能被查到,以及怎么解决。
编译好之后,在项目中可以加进来这个库,写了个demo来试试这个库:
这样的风格比单纯用API好多了,而且是跨平台的。
那么我写的demo是使用windows平台下的dev-c++来做的,如果你用dev-c++,那么首先有1个问题要解决:
http://blog.csdn.net/jimmy_w/archive/2007/12/24/1965313.aspx
这里有解释为什么模板化基类里的名称不能被查到,以及怎么解决。
编译好之后,在项目中可以加进来这个库,写了个demo来试试这个库:
#include
"
zthread/Thread.h
"
#include " zthread/Runnable.h "
#include < iostream >
class RunThread: public ZThread::Runnable {
public:
RunThread(int nID=0):id(nID){}
~RunThread(){std::cout<<"Thread "<<id<<" exit"<<std::endl;}
void run()
{
for(int i=0;i!=10;++i){
std::cout<<"Thread "<<id<<" is running "<<std::endl;
}
}
private:
int id;
} ;
int main()
{
try{
ZThread::Thread t1(new RunThread(1));
ZThread::Thread t2(new RunThread(2));
}catch(ZThread::Synchronization_Exception &err){
std::cerr<<err.what()<<std::endl;
}
system("pause");
return 0;
}
#include " zthread/Runnable.h "
#include < iostream >
class RunThread: public ZThread::Runnable {
public:
RunThread(int nID=0):id(nID){}
~RunThread(){std::cout<<"Thread "<<id<<" exit"<<std::endl;}
void run()
{
for(int i=0;i!=10;++i){
std::cout<<"Thread "<<id<<" is running "<<std::endl;
}
}
private:
int id;
} ;
int main()
{
try{
ZThread::Thread t1(new RunThread(1));
ZThread::Thread t2(new RunThread(2));
}catch(ZThread::Synchronization_Exception &err){
std::cerr<<err.what()<<std::endl;
}
system("pause");
return 0;
}
这样的风格比单纯用API好多了,而且是跨平台的。