在DEV-C++和VC 7.1中使用zthread线程库

在Dev-C++,VC7.1中使用ZThread   

ZThread是IBM公司 Eric Crahen使用C++所编写的跨平台线程库
([url]http://zthread.sourceforge.net)[/url]

最近同时使用windows和linux两个平台,对平台无关性更加关注。
多线程是现在的程序基本要用到的,跨平台库有一些。   

先看一看ZThread吧。

到[url]http://zthread.sourceforge.net/download.html[/url]下载 2.3.1的release,解压,得到所需的源码。

当然,要编译一个例程试试,先用Dev-C++建一个项目看一看。

  1、建好一个控制台项目,把[url]http://zthread.sourceforge.net/html/classZThread_1_1Thread.html[/url]页面的
     Waiting for a task 例子copy至main.cpp。
  2、在Project Options -> Directories -> Include Directories 中加入 ZThread-2.3.1所在目录
  3、此时link时还会有link error,在项目中加一目录ZThread(当然不加目录也可,但这样看起来整洁),
     将 ZThread-2.3.1\src 目录下的.cxx加入此目录。
  4、按下 F9(Complie&Run),可以看到想要的结果了。  
     
Dev-C++做小程序学习一把还是很不错的,大项目我没试过,自已用得多的还是VC 7.1 (Visual Studio.Net 2003)。
再到VC7.1下试试

1、同上
2、同上
3、这里要注意,ZThread-2.3.1\src下还有一个win32目录,
    这次加.cxx时,src目录下的 ThreadOps.cxx要用src/win32下的代替,不然还会有报错。
4、还要改一个选项:Property pages->Configurations properties->C/C++ ->Precompiled Headers
    - Create/Use Precompiled Head  改选 Not using Precompiled Headers 项
5、...

ZThread 在使用上感觉还是比较优雅的,比较不错的说

阅读更多

编译ZThread线程库出错,求救!

08-18

编译ZThread出错, 帮帮忙看看出错信息rnrngcc 3.3.4 编译第三方线程库ZThread:rnrn#export ZT_POSIXrn#./configurernrnchecking build system type... i686-pc-linux-gnurnchecking host system type... i686-pc-linux-gnurnchecking target system type... i686-pc-linux-gnurnchecking for a BSD-compatible install... /usr/bin/install -crnchecking whether build environment is sane... yesrnchecking for gawk... nornchecking for mawk... mawkrnchecking whether make sets $(MAKE)... yesrnLoading m4 macros from sharernchecking for g++... g++rnchecking for C++ compiler default output... a.outrnchecking whether the C++ compiler works... yesrnchecking whether we are cross compiling... nornchecking for suffix of executables...rnchecking for suffix of object files... ornchecking whether we are using the GNU C++ compiler... yesrnchecking whether g++ accepts -g... yesrnchecking for style of include used by make... GNUrnchecking dependency style of g++... gcc3rnchecking for gcc... gccrnchecking whether we are using the GNU C compiler... yesrnchecking whether gcc accepts -g... yesrnchecking for gcc option to accept ANSI C... none neededrnchecking dependency style of gcc... gcc3rnchecking how to run the C preprocessor... gcc -Ernchecking for egrep... grep -Ernchecking for ANSI C header files... nornchecking for sys/types.h... yesrnchecking for sys/stat.h... yesrnchecking for stdlib.h... yesrnchecking for string.h... yesrnchecking for memory.h... yesrnchecking for strings.h... yesrnchecking for inttypes.h... yesrnchecking for stdint.h... yesrnchecking for unistd.h... yesrnchecking pthread.h usability... yesrnchecking pthread.h presence... yesrnchecking for pthread.h... yesrnchecking for linker option -pthread... nornchecking for linker option -lpthread... nornchecking for sched_get_priority_max in -lrt... nornchecking for sched_yield... nornchecking for pthread_yield... nornchecking for pthread_key_create... nornchecking for pthread_keycreate... nornchecking for doxygen... norndetecting for ftime() functionrnchecking sys/time.h usability... yesrnchecking sys/time.h presence... yesrnchecking for sys/time.h... yesrnchecking for _ftime()... nornchecking sys/timeb.h usability... yesrnchecking sys/timeb.h presence... yesrnchecking for sys/timeb.h... yesrnchecking for ftime()... nornerror!rnrn我该怎么办? (编译环境是linux2.4.26 i686 gcc 3.3.4 glibc 支持-pthread)rn谢谢您的热心答复!

线程ZThread问题

09-24

编译器:DEVrn库已编译rn//源文件 BasicThread.cpprn#pragma comment (lib,"ZThread.a")rn#include rn#include "LiftOff.h"rn#include "ZThread/Thread.h"rn#include "ZThread/ZThread.h"rnusing namespace ZThread;rnusing namespace std;rnrnint main() rn try rn Thread t(new LiftOff(10));rn cout << "Waiting for LiftOff" << endl;rn catch(Synchronization_Exception& e) rn cerr << e.what() << endl;rn rn return 0rn ///:~rn//-------------------------------------------------------rn//LiftOff.hrn//#pragma comment (lib,"ZThread.a")rn#ifndef LIFTOFF_Hrn#define LIFTOFF_Hrn#include rn#include "ZThread/Runnable.h"rnrnclass LiftOff : public ZThread::Runnable rn int countDown;rn int id;rnpublic:rn LiftOff(int count, int ident = 0) :rn countDown(count), id(ident) rn ~LiftOff() rn std::cout << id << " completed" << std::endl;rn rn void run() rn while(countDown--)rn std::cout << id << ":" << countDown << std::endl;rn std::cout << "Liftoff!" << std::endl;rn rn;rn#endif // LIFTOFF_H ///:~rnrn报错如下:rn[Linker Error] undefined reference to `ZThread::Thread::Thread(ZThread::Task const&, bool)'rn[Linker Error] undefined reference to `ZThread::Thread::~Thread()'rn[Linker Error] undefined reference to `ZThread::Thread::~Thread()'rn[Linker Error] undefined reference to `ZThread::AtomicCount::operator--()'rn[Linker Error] undefined reference to `ZThread::AtomicCount::~AtomicCount()'rn[Linker Error] undefined reference to `ZThread::AtomicCount::AtomicCount()'rn[Linker Error] undefined reference to `ZThread::AtomicCount::operator++(int)'rn请问这是怎么回事?

没有更多推荐了,返回首页