[Interest] QThread and sleep
Thiago Macieira
thiago.macieira at intel.com
Tue Mar 19 19:58:43 CET 2013
On terça-feira, 19 de março de 2013 15.15.31, Hugo Drumond Jacob wrote:
> 2013/3/19 Thiago Macieira <thiago.macieira at intel.com>:
> > On terça-feira, 19 de março de 2013 14.56.47, Hugo Drumond Jacob wrote:
> >> No problem! In fact, we are using! It's just a question about
> >> QThread::wait and QThread::sleep: "It's safe use QThread::wait in
> >> other situation that not synchronously QThread::terminate ?" and you
> >> already answered: yes. Maybe not for this point of our application in
> >> specific, but is normal usage.
> >
> > They are two very different methods and do not do remotely the same thing.
> > Asking about the two together in the same breath would suggest that you do
> > not understand what they are or what you're trying to do.
> >
> > Anyway, QThread::wait() is perfectly safe to use. It's
> > QThread::terminate()
> > that is not safe.
>
> Yes! I agree: "QThread::wait and QThread::terminate are two very
> different methods and do not do remotely the same thing.". I'm asking
> about QThread::wait and QThread::sleep
That's what I answered. Sorry if I was not clear.
Besides the fact that both have one parameter containing a time in
milliseconds, they are very different and do not do remotely the same thing.
wait() waits for the started thread to exit up to the timeout amount of
milliseconds, but may return sooner (even immediately) if the thread exits
sooner (or has exited already).
sleep() suspends the execution of the calling thread, whichever that thread
is, for the amount of milliseconds and it cannot be interrupted. But, of
course, it's not precise: the thread may be resumed at a later time, depending
on OS scheduling.
> , but, Qt documentation suggest
> "Use QThread::wait() after terminate() for synchronous termination.".
> Some careless reader can understand "ONLY use QThread::wait() after
> QThread::terminate()". As you say, it's safe (but not recommended) use
> QThread::wait().
Yes, especially if the thread exits by normal means (quit, exit, return from
run()).
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130319/1da327db/attachment.sig>
More information about the Interest
mailing list