[Qt-interest] Qt 4 with no threads

Thiago Macieira thiago.macieira at trolltech.com
Thu Apr 9 00:34:01 CEST 2009


Justin Noel wrote:
>Qt itself does not use any threads internally.

That's not entirely correct.

Qt uses threads on its own in two places: QProcess and QHostInfo. The 
former is the proper way of handling the SIGCHLD handler in a 
multithreaded environment: since the signal can be delivered to any 
thread, that thread writes to a pipe that wakes up the process manager's 
thread, which in turn handles the changing of QProcess states (that 
requires mutex locking, which is why the SIGCHLD handler can't do it).

However, that's only necessary because of multithreading: if the program 
is single-threaded, then you know which thread has to be woken up from 
sleep in order to run waitpid(2).

The second case, however, is because the hostname resolution calls 
(getaddrinfo, gethostbyname, etc.) are all blocking. There's no solution 
for this: if you can't use threads, you must place those calls in the GUI 
thread, which means the application could freeze for up to 30 seconds if 
the DNS server isn't properly configured.

Well, I take that back: there is a workaround: to use a helper sub-
process. It's ugly, but it may work.

-- 
Thiago Macieira - thiago.macieira (AT) nokia.com
  Senior Product Manager - Nokia, Qt Software
      Sandakerveien 116, NO-0402 Oslo, Norway
-------------- 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/20090409/89a88158/attachment.bin 


More information about the Qt-interest-old mailing list