I have a problem with vector in my program. I found many similar problems but no solution. This code is in new thread:
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";
}
}
the output is:
action!
try remove the action!
Segmentation fault
actions is a vector< action>
struct action{
string query;
long size;
void operator()(){
cout << "action!\n";
}
};
update
The real problem is: struct with this method already destroyed.
class mthread{
...
deque<action> actions;
...
operator(){
(loop above)
}
};
class mthread_holder{
mthread* mt;
operator()(){
(*mt)();
}
mthread_holder(mthread *p){
mt = p;
}
};
then I just use:
threads.back().thrd = new boost::thread(mthread_holder(mthrd));
I think, I need to store it more safely
How can i store the callable in the thread and hold pointer to it without boost::bind?