1
我在我的節目向量的問題。我發現很多類似的問題,但沒有解決方案此代碼是在新線程:C++分割失敗上vector.erase()
while(status == RUN){
msleep(20);
while(status != DESTROY && (!actions.empty())){
item = actions.begin();
(*item)();
cout<< "try remove the action!\n";
item=actions.erase(actions.begin());
cout << "everything ok!\n";
}
}
輸出爲:
action!
try remove the action!
Segmentation fault
行動是一個矢量<動作>
struct action{
string query;
long size;
void operator()(){
cout << "action!\n";
}
};
更新
真正的問題是:與此結構方法已經被破壞。
class mthread{
...
deque<action> actions;
...
operator(){
(loop above)
}
};
class mthread_holder{
mthread* mt;
operator()(){
(*mt)();
}
mthread_holder(mthread *p){
mt = p;
}
};
然後我就用:
threads.back().thrd = new boost::thread(mthread_holder(mthrd));
我想,我需要存儲更安全
我怎樣才能調用存儲在線程並保持指針它沒有提升: :綁定?
我發現真正的問題。線程對象在此循環開始之前銷燬。 – 2011-03-31 05:35:25