首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 服务器 > 其他服务器 >

solaris初学者求教boost thread有关问题~

2012-03-23 
solaris菜鸟求教boost thread问题~~尝试用boost::thread写了一个多线程的测试,大概内容如下:C/C++ code#in

solaris菜鸟求教boost thread问题~~
尝试用boost::thread写了一个多线程的测试,大概内容如下:

C/C++ code
#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;};




main函数那边是这样写的:
C/C++ code
#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;}


这个测试大概就是A1中的函数一直运行,希望通过A2中的函数的变化去控制A1中的函数的执行。我想尝试的东西是在单件模式下线程之间的控制。



这样写好后在windows下编译可以通过没有问题。

可是拿到solaris下用sunstudio编译则无法通过,显示的错误如下:
"boost/exception_ptr.hpp", line 111: Warning: Function boost::exception_ptr::~exception_ptr() can throw only the exceptions thrown by the function boost::exception_detail::exception_ptr_base::~exception_ptr_base() it overrides.
1 Warning(s) detected.
ux-4800 --> 1 job
mkdir -p dist/Debug/SunStudio_12.1-Solaris-Sparc
CC -mt -o dist/Debug/SunStudio_12.1-Solaris-Sparc/testcpu build/Debug/SunStudio_12.1-Solaris-Sparc/_ext/appuser/huangxu/testCPU/../thread_sin.o
ux-4800 --> Job output
mkdir -p dist/Debug/SunStudio_12.1-Solaris-Sparc
CC -mt -o dist/Debug/SunStudio_12.1-Solaris-Sparc/testcpu build/Debug/SunStudio_12.1-Solaris-Sparc/_ext/appuser/huangxu/testCPU/../thread_sin.o
Undefined first referenced
 symbol in file
boost::thread::~thread() build/Debug/SunStudio_12.1-Solaris-Sparc/_ext/appuser/huangxu/testCPU/../thread_sin.o
boost::detail::thread_data_base::~thread_data_base #Nvariant 1() build/Debug/SunStudio_12.1-Solaris-Sparc/_ext/appuser/huangxu/testCPU/../thread_sin.o
void boost::thread::start_thread() build/Debug/SunStudio_12.1-Solaris-Sparc/_ext/appuser/huangxu/testCPU/../thread_sin.o
boost::detail::thread_data_base::__vtbl build/Debug/SunStudio_12.1-Solaris-Sparc/_ext/appuser/huangxu/testCPU/../thread_sin.o


[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,我加上以后就报这个错误了,研究了老半天还是云里雾里的,网上也没找到关于这个问题的介绍。有没有哪些高人给小弟指点一二?

非常感谢~~!

[解决办法]
不懂,但是帮你顶一下!

热点排行