solaris菜鸟求教boost thread问题~~
时间:2011-09-21
来源:互联网
尝试用boost::thread写了一个多线程的测试,大概内容如下:
C/C++ code
main函数那边是这样写的:
C/C++ code
这个测试大概就是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,我加上以后就报这个错误了,研究了老半天还是云里雾里的,网上也没找到关于这个问题的介绍。有没有哪些高人给小弟指点一二?
非常感谢~~!
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,我加上以后就报这个错误了,研究了老半天还是云里雾里的,网上也没找到关于这个问题的介绍。有没有哪些高人给小弟指点一二?
非常感谢~~!
作者: Ast86318307 发布时间: 2011-09-21
不会吧。。。这么久都没个人回复的。。。
作者: Ast86318307 发布时间: 2011-09-26
不懂,但是帮你顶一下!
作者: vinnda 发布时间: 2011-09-26
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28