solaris菜鸟求教boost thread问题~~
尝试用boost::thread写了一个多线程的测试,大概内容如下:
#include <boost/thread/thread.hpp>#include <boost/bind.hpp>#include <iostream>using namespace std;void wait(int seconds) { boost::this_thread::sleep(boost::posix_time::seconds(seconds)); } class A2{ DEFINE_SINGLETON(A2) //定义为单件模式;public: A2() { t = 0; bStop = false; }public: void dis() { bStop = false; while(t < 5) { cout<<"A2 display running..."<<endl; wait(1); ++t; } cout<<"A2 displaying is stopped"<<endl; bStop = true; } bool stop() { return bStop; }private: bool bStop; int t;};class A1{ DEFINE_SINGLETON(A1)public: A1() { i = 0; j = 0; a = 'a'; bEnd = false; } void disp() { cout<<"i = "<<i<<endl; i++; cout<<"After, i = "<<i<<endl; cout<<endl; cout<<endl; cout<<"a is "<<a<<endl; a = a+1; cout<<"After, a is "<<a<<endl; } void stay() { bEnd = false; while(false == A2::getInstRef().stop()) { cout<<"***"<<endl; wait(1); } cout<<"thread B stopped by A2 display"<<endl; cout<<endl; bEnd = true; } bool stay_end() { return bEnd; }private: int i; int j; bool bEnd; char a;};
#include <boost/shared_ptr.hpp>int main(int argc, char* argv[]){ int iEnd; boost::shared_ptr<boost::thread> testA(new boost::thread(boost::bind(&A2::dis, A2::getInstPtr()))); boost::shared_ptr<boost::thread> testB(new boost::thread(boost::bind(&A1::stay, A1::getInstPtr()))); cout<<endl; // boost::shared_ptr<boost::thread> testB(boost::bind(&A2::dis, A2::getInstPtr())); cin>>iEnd; return 0;}
[Hint: try checking whether the first non-inlined, non-pure virtual function of class boost::detail::thread_data_base is defined]
ld: fatal: Symbol referencing errors. No output written to dist/Debug/SunStudio_12.1-Solaris-Sparc/testcpu
*** Error code 1
dmake: Fatal error: Command failed for target `dist/Debug/SunStudio_12.1-Solaris-Sparc/testcpu'
Current working directory /appuser/huangxu/testCPU
*** Error code 1
dmake: Fatal error: Command failed for target `.build-conf'
Current working directory /appuser/huangxu/testCPU
*** Error code 1
dmake: Fatal error: Command failed for target `.build-impl'
Build failed. Exit value 1.
这个错误是什么意思呢?是thread里面的析构函数出问题了吗?第一次编译的时候说不支持多线程,让我在工程属性里加上 -mt,我加上以后就报这个错误了,研究了老半天还是云里雾里的,网上也没找到关于这个问题的介绍。有没有哪些高人给小弟指点一二?
非常感谢~~!
[解决办法]
不懂,但是帮你顶一下!