bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Thread::isRunning() returning false even though thread hasn't fully term


From: Matt Scifo
Subject: Thread::isRunning() returning false even though thread hasn't fully terminated
Date: Wed, 19 Nov 2003 12:29:07 -0800

Hello

I have a list of pointers to Thread objects.

list< Thread * > instances;

When it comes time to terminate my threads, I have a for loop iterate
over the list and call destroy_instance().  destroy_instance() sets a
termination flag that is being checked for in the thread's run() method.

    for (list< Thread * >::iterator it = instances.begin(); it !=
instances.end(); it++)
    {
        cout << "Terminating " << name << " thread." << endl;
        destroy_instance((*it));
    }

Now all threads have been told to terminate and are finishing their
operations until they come to the check point and see that they have
been told to exit the run() method.

To ensure that I don't proceed until all my threads have terminated, I
continue to iterate through the list of threads, checking if they are
still running.  If isRunning() returns false, then I delete the thread
object, remove it from the list, and repeat the iteration until all
threads return false on isRunning() and they have been deleted.

    while (instances.size() > 0)
    {
        for (list< Thread * >::iterator it = instances.begin(); it !=
instances.end(); it++)
        {
            if (!(*it)->isRunning())
            {
                cout << "Deleting " << name << " instance." << endl;
                delete (*it);
                instances.erase(it);
                cout << instances.size() << " threads remaining.\n";
                break;
            }
        }
    }


I am debugging in GDB and receive a message when each thread exits...
[Thread -1214117072 (zombie) exited]

This indicates that the thread has finished but the object has yet to be
deleted.

The problem I am facing is that I am receiving notification from GDB
that the threads are exiting after I have already deleted them.  Why is
Thread::isRunning() reporting that the thread is not running when in
fact GDB shows that the thread hasn't actually terminated yet?

Output from running in GDB...
<snip>
Terminating MyThread thread.
Terminating MyThread thread.
Terminating MyThread thread.
Terminating MyThread thread.
Terminating MyThread thread.
Terminating MyThread thread.
Terminating MyThread thread.

MyThread::final() called
MyThread::final() called
MyThread::final() called
MyThread::final() called
MyThread::final() called
MyThread::final() called
MyThread::final() called

Deleting MyThread instance.
MyThread::~MyThread called
6 threads remaining.
Deleting MyThread instance.
MyThread::~MyThread called
5 threads remaining.
Deleting MyThread instance.
MyThread::~MyThread called
4 threads remaining.
Deleting MyThread instance.
MyThread::~MyThread called
3 threads remaining.
Deleting MyThread instance.
MyThread::~MyThread called
2 threads remaining.
Deleting MyThread instance.
MyThread::~MyThread called
1 threads remaining.
Deleting MyThread instance.
MyThread::~MyThread called
0 threads remaining.

/*  
   At this point, all thread objects have been successfully deleted.
   Why do they only begin to actually terminate until after the    
   objects have deleted.  If isRunning() is not supposed to tell me 
   when the thread truly stops, then I need something that can.
*/

[Thread 1167313712 (zombie) exited]
[Thread 1805159216 (zombie) exited]
[Thread 1226062640 (zombie) exited]
[Thread 1544985392 (zombie) exited]
[Thread 1419094832 (zombie) exited]
[Thread 1234455344 (zombie) exited]
[Thread 1242848048 (zombie) exited]
</snip>

RH9, g++ 2.9.6, commoncpp2 1.0.13

Can anyone please explain?


Matt Scifo







reply via email to

[Prev in Thread] Current Thread [Next in Thread]