Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, April 2007
QThread::terminated/finished


Message 1 in thread

The qt4.3 documentation says:

QThread::finished
This signal is emitted when the thread has finished executing.

QThread::terminated
This signal is emitted when the thread is terminated.

It is clear, that when the thread finishes normally, finished() is
emitted and when the thread is terminated by terminate(), terminated
is emitted. But when the thread is terminated, it can be percieved
that "it finished executing" and finished() should be then probably
called too, right? And if the thread finishes executing, it can be
counted as being terminated gracefully, maybe? Documentation is not
very detailed in this matter. Is there any defined order in which
terminated/finished is called?

Basically, what I am trying to do is to delete "thread-representing
treeitem" and the thread itself as soon as it finishes executing, by
reacting to terminated(). But if I do it too early (while something
from the thread-to-be-deleted is on call stack), I get a segfault just
a bit later :)

Martin Petricek

--
 [ signature omitted ] 

Message 2 in thread

BH wrote:
> The qt4.3 documentation says:
> 
> QThread::finished
> This signal is emitted when the thread has finished executing.
> 
> QThread::terminated
> This signal is emitted when the thread is terminated.
> 
> It is clear, that when the thread finishes normally, finished() is
> emitted and when the thread is terminated by terminate(), terminated
> is emitted. But when the thread is terminated, it can be percieved
> that "it finished executing" and finished() should be then probably
> called too, right? And if the thread finishes executing, it can be
> counted as being terminated gracefully, maybe? Documentation is not
> very detailed in this matter. Is there any defined order in which
> terminated/finished is called?
> 
> Basically, what I am trying to do is to delete "thread-representing
> treeitem" and the thread itself as soon as it finishes executing, by
> reacting to terminated(). But if I do it too early (while something
> from the thread-to-be-deleted is on call stack), I get a segfault just
> a bit later :)
> 
> Martin Petricek
> 
> -- 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

void QThread::terminate ()   [slot]

Terminates the execution of the thread. The thread may or may not be 
terminated immediately, depending on the operating systems scheduling 
policies. Use QThread::wait() after terminate() for synchronous 
termination.
When the thread is terminated, all threads waiting for the thread to 
finish will be woken up.
Warning: This function is dangerous and its use is discouraged. The 
thread can be terminate at any point in its code path. Threads can be 
terminated while modifying data. There is no chance for the thread to 
cleanup after itself, unlock any held mutexes, etc. In short, use this 
function only if absolutely necessary.
Termination can be explicitly enabled or disabled by calling 
QThread::setTerminationEnabled(). Calling this function while 
termination is disabled results in the termination being deferred, until 
termination is re-enabled. See the documentation of 
QThread::setTerminationEnabled() for more information.

--
 [ signature omitted ]