[Qt-interest] Multithreading - yield function
Andreas Pakulat
apaku at gmx.de
Mon Aug 31 20:42:42 CEST 2009
On 31.08.09 21:09:12, Patric wrote:
> And how do you know that it didn't yield?
>
> Yielding execution means allowing other threads to execute, while the
> calling
> thread is suspended. Eventually, however, the calling thread will resume
> working. So the "some other code" line *will* be executed, eventually.
>
> Anyway, whether the yielding actually does anything depends on the operating
> system and the scheduling priorities of the runnable threads. Like Thomas
> said, if there are no threads waiting to be executed, there will be no
> yielding. But even if there are other threads waiting, they may be of lower
> priority, so yielding will do nothing. You may have to exhaust your
> timeslice
> instead.
>
> Finally, why do you need to yield? It's just a hint to the operating system.
> It may decide to ignore it.
>
>
> ----------------------------------------------------------------------------------
> Hi Thiago,
> I'm using the debugger with multiple breakpoints and because of that I know
> if it's yielding or not. By default all threads priorities should be equal.
> I'm sure there is one thread that is waiting.
>
> I need to yield it because my logic requires it. I'm using queued
> connections here and it's very important to know that the destination slot
> is emitted before the thread continues.
Then either don't use queued connections but direct ones, or use the
usual thread-communication mechanisms to make your thread stop at that
point until the receiving thread is done with the slot. You could do
this for example with a QWaitCondition.
Andreas
--
You will become rich and famous unless you don't.
More information about the Qt-interest-old
mailing list