[Qt-interest] Multithreading - yield function
Thiago Macieira
thiago.macieira at trolltech.com
Mon Aug 31 22:37:18 CEST 2009
Em Segunda-feira 31. Agosto 2009, às 21.46.20, você escreveu:
> I will consider that, I don't have much experience with threads.
>
> One thing I don't understand, why there would be a function like yield that
> don't always work. What is the reason such a function to exist if it's not
> good to use it.
> Sorry if my questions are obvious or something like that. :)
The function works.
It just doesn't do what you expect it to do. You're expecting that another
thread gets woken up and run, while your thread is suspended for a long time.
That's not what happens. That only causes the current thread to give up its
processor time. Other threads may wake up, if they are ready for execution.
But the current thread will wake up too, very soon.
If you don't insert a synchronisation primitive, like a QWaitCondition or a
QSemaphore, there's no guarantee of how long your thread will get suspended
for. It may get suspended but then woken up again before the other thread
finishes execution.
If you want to program with threads, I recommend you read some books on the
subject first. It is *very* tricky to get it right. Programming threads when,
like you said, you don't have much experience, is a very daunting task.
--
Thiago Macieira - thiago.macieira (AT) nokia.com
Senior Product Manager - Nokia, Qt Development Frameworks
Sandakerveien 116, NO-0402 Oslo, Norway
Qt Developer Days 2009 | Registration Now Open!
Munich, Germany: Oct 12 - 14 San Francisco, California: Nov 2 - 4
http://qt.nokia.com/qtdevdays2009
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090831/154fc03c/attachment.bin
More information about the Qt-interest-old
mailing list