Linux下安装 ZThread 2.3.2
来源:互联网 发布:矩阵变换器 编辑:程序博客网 时间:2024/05/24 15:41
1 下载 ZThread 2.3.2 zthread.sourceforge.net/download.html
2 解压以后进行安装
1)./configureCXXFLAGS=-fpermissive //千万不要少了CXXFLAGS=-fpermissive,否则在make的时候会报错。
2)sudo make
3)sudo make install
thread库的用法和Java的多线程很相似,名字都差不多,比如Thread,Runnable,^_^
举个例子入门一下吧
在zthread里有一个任务的概念,任务就是要做的一件事,任务是怎么定义呢?
两件事要做:
一、继承Runnable这个抽象类。
二、实现run接口
Runnable在源代码中的定义如下:
classRunnable{
public:
virtual void run() = 0;
virual ~Runnable(){}
}
我们现在定义一个任务,这个任务用来数数吧
//File:Counter.cpp
#include<iostream>
#include<zthread/Runnable.h>
#include<zthread/Thread.h>
usingnamespace std;
using namespace ZThread; // Zthread所有的变量,类等都在这个名字空间内
classCounter : public Runnable
{
private:
int_id; // 任务的ID号
int_num; // 当前数到几
public:
Counter(int id):_id(id){}
voidrun() // 实现run函数
{
_num = 1;
while(_num <=50 )
{
cout <<_id << " " << _num <<endl;
_num++;
}
}
};
intmain()
{
try
{
in id = 1;
Thread t(new Counter(id));
}
catch(Synchronization_Exception& e)
{
cerr << e.what() <<endl;
}
}
// end offile
然后编译它
g++ -otest Counter.cpp -lZThread
最后边的一个选项是编译时候动态连接到libZThread库
然后运行吧
./test
如果报错的话,按下边方式运行
LD_LIBRARY_PATH=/usr/local/lib/
这就是基本线程运行的例子了.
- Linux下安装 ZThread 2.3.2
- linux安装zthread
- windows下编译ZThread-2.3.2
- 在linux下使用ZThread
- ubuntu 下 zthread 安装(开发工具eclipse)
- linux下第三方库(ZThread)的安装,eclipse配置
- c++线程库ZThread在Linux上的安装
- linux下第三方库(ZThread)的安装,eclipse配置
- zthread库(version 2.3.2)在gcc 3.4.2下编译问题的解决方法
- ZThread在VC6下的构建
- windows平台下编译zThread库
- ZThread库的配置,Windows&Linux
- ZThread在Dev-C++上的安装与配置
- Linux下安装 jboss4.2
- LINUX下安装ORACLE10.2
- linux 下安装 postgres8.2
- Linux下安装matlab(2)
- Linux下安装Oracle11gR2 2
- 在北京大学2008年开学典礼上的发言
- PHP实现文件的上传及下载
- 路由器Loopback口的作用汇总
- 命令杂项
- hdu 2560 Buildings(超水)
- Linux下安装 ZThread 2.3.2
- 关于程序员的笑话(七)
- asp.net 控件的 ID ,ClientID ,UniqueID 区别
- MyEclipse使用经验总结
- 有关vc和teechart的话题
- 彻底删除Oracle!
- session 与 cookie
- 局部Const 常量!今天学到啦~
- android实现开机自启动服务