I have a class which has attribute thread. It looks something like this.
class myClass {
public:
myClass(ClassB * x) {
myThread = thread(&myClass::run, this);
classB = x;
}
~myClass() { myThread.detach(); }
void run() {
while (something) {
// do your work.
}
classB->endThisObject(this);
}
private:
thread myThread;
ClassB * classB;
}
My classB looks like this.
ClassB {
public:
endThisObject(myClass * x) { delete x; }
}
So basically the last operation of myThread is destroying itself using another object. Is it okey or this can cause many troubles ? I was testing in on my code and I had no leaks but this seems kinda wrong to me.