Hi ,

I have a thread created in main thread which is created in the heap.

Up on some user input i need to terminate this thread.

I have written a fuction TerminateThread

TerminateThread()
{
m_mutex.lock()
m_flag = true; // m_mutex and m_flag are global. The other thread will check this flag after some operations, if the flag is set ,it will call terminate( return).
m_mutex.unlock();
delete m_thread ;
//Delete statement is giving an error saying trying to delete a running thread.

So i replaced the code with this
// Since after the thread terminates m_thread->isRunning() = false
while ( m_thread->isRunning()) {
wait(4000); //This is making the thread to wait indefinetly.
}

}

I have also tried
m_thread->terminate()
m_thread->wait(); // Never returns from the wait call
But even this is not working.

Thanks.