【发布时间】:2011-11-07 11:59:17
【问题描述】:
我大约一个小时前开始做线程,但在调试模式达到我期望的效果和发布模式兑现时遇到了一些麻烦。
调试
g++ -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/foo.o.d -o build/Debug/GNU-Linux-x86/foo.o foo.cpp
随便 2222222222
发布
g++ -c -O2 -MMD -MP -MF build/Release/GNU-Linux-x86/foo.o.d -o build/Release/GNU-Linux-x86/foo.o foo.cpp
随便
RUN FAILED(退出值1,总时间:49ms)
类
#include "foo.h"
#define NUMINSIDE 10
foo::foo()
{
inside = new int[NUMINSIDE];
}
void foo::workerFunc(int input)
{
for (int i = 0; i < NUMINSIDE; i++)
{
inside[i] += input;
}
}
void foo::operate()
{
std::cout << "Whatever" << std::endl;
boost::thread thA(boost::bind(&foo::workerFunc, this, 1));
boost::thread thB(boost::bind(&foo::workerFunc, this, 1));
thA.join();
thB.join();
for (int i = 0; i < NUMINSIDE; i++)
{
std::cout << this->inside[i] << std::endl;
}
}
主要
int main(int argc, char** argv)
{
foo* myFoo = new foo();
myFoo->operate();
return 0;
}
【问题讨论】:
-
这看起来不错,foo.h 的内容是什么?
-
我看不到任何可能导致“RUN FAILED”输出的代码,所以问题可能出在您没有显示的某些代码中?
标签: c++ multithreading debugging gcc boost-thread