D
Dilip
Is my understanding right here?
An object becomes totally inaccessible only after its dtor runs through
completely, right?
I have a situation where I need to hang around in the dtor of an
automatic object for a while -- this is to let various threads that
have access to my automatic object shutdown gracefully.
I do not want main() to return when myclass::runInfinitely() happens to
throw an exception without giving a chance for worker threads to die.
Currently I do it like this:
int main()
{
try
{
myclass myclassObj;
spawnthreads(&myclassObj);
myclass.runInfinitely();
}
catch(...)
{
}
}
~myclass()
{
while (threadsarestillrunning)
{
sleepsome();
}
}
while the above loop is executing, other threads that still hold a
pointer to myclass can safely access member variables and call methods,
right?
An object becomes totally inaccessible only after its dtor runs through
completely, right?
I have a situation where I need to hang around in the dtor of an
automatic object for a while -- this is to let various threads that
have access to my automatic object shutdown gracefully.
I do not want main() to return when myclass::runInfinitely() happens to
throw an exception without giving a chance for worker threads to die.
Currently I do it like this:
int main()
{
try
{
myclass myclassObj;
spawnthreads(&myclassObj);
myclass.runInfinitely();
}
catch(...)
{
}
}
~myclass()
{
while (threadsarestillrunning)
{
sleepsome();
}
}
while the above loop is executing, other threads that still hold a
pointer to myclass can safely access member variables and call methods,
right?