[Qt-interest] Multithreading - yield function

Thiago Macieira thiago.macieira at trolltech.com
Mon Aug 31 19:46:07 CEST 2009


Em Segunda-feira 31 Agosto 2009, às 19:15:37, Patric escreveu:
> Hello Thomas,
> 
> emit some signal
> yieldCurrentThread();
> 
> some other code
> 
> 
> 
> if this method was working, the last line should not have been executed.
>  But it executes.
> 
> The current thread is just passing by the yieldCurrentThread() function.
> 
> 
> 
> And I'm saying somethimes, because I'm actually not sure if it'll yield the
> execution at some later point... but it should do it immidiately after the
> function call.
> 
> 
> 
> William, yes it works. But this is a workaround, the yield function should
> be working.

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.

-- 
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/cdde46d0/attachment.bin 


More information about the Qt-interest-old mailing list