considering following class
class test{
private: long long id;
//some field....
public: test(){};
void do_something(){
//some huge operations....
}
void do_something_else(void* arg){
//yet another huge work load.....
}
}
///////////////////////////
void* _thread(void* _ins){
test* ins=(test*)_ins;
//some work
if(<<some condition>>){delete ins;}//not thread safe, std::auto_ptr doesn't help anymore
}
///////////////////////////
int main(){
test *ins=new test();
//pass the ins to 10 thread.
}
consider there are 10 threads using a shared object, when ever one of a thread delete the object, program exit.
Questions:
how can I get any error/exception at runtime when object gets deleted? try-catch
didn't help. any solution?!
is there any thread-safe and consistence way to count the current thread using this object?
is there any event-based solution to fire an event when object is ready for purging?
thanks in advance.