Reputation: 6008
Can this concept work?
class MyClass
{
public:
~MyClass()
{
MyMutex.acquire();
}
void ThreadFunction(void* param)
{
MyMutex.acquire();
//do something
MyMutex.release();
}
};
Also Let's say we have an object of this class, call it "inst"
What I am trying to achieve is that if:
inst->ThreadFunction
delete inst
then this call will hang until ThreadFunction releases the mutex.Is that ok to do?
Upvotes: 0
Views: 343
Reputation: 5083
It would be much better to create a wrapper around MyClass
if MyClass
contains resources. Its even worse if the program uses a class that inherits from MyClass
, because the destructor for ChildofMyClass
will have already been called by this point.
Upvotes: 3