c++ - What happens when object is destroyed when it is stuck in an infinite loop? -
i want know happen when destructor gets called on object when object stuck in infinite while loop in different thread.
// main thread creates object myclass _obj = new myclass(): // doing stuff delete _obj;
where,
myclass::myclass() { // start thread calls myclass::mypollingfn() } myclass:: mypollingfn() { // runs in new child thread while(true) { // doing work // sleep(5 seconds) } }
explanation: there class object of myclass creates thread , runs mypollingfn method in infinite loop. every iteration of method can change class variables. ok destroy object parent thread holds object? there possibility of giving issue?
if mypollingfn
ever touches this
, explicitly or implicitly (e.g. accessing non-static member variables), code exhibit undefined behavior, this
become dangling pointer.
and if doesn't touch this
, why make non-static member function?
Comments
Post a Comment