[Qt-interest] QGraphicsItem and Threads

Thiago Macieira thiago at kde.org
Tue Oct 20 16:03:36 CEST 2009


Em Terça-feira 20 Outubro 2009, às 11:02:42, você escreveu:
> AFAIK Win32 allows GUI operations in any thread - but all the operations
>  for a given window must be done in the same thread.  I suspect all child
>  windows belonging to the same parent have to be in the same thread as
>  well.  I believe X is the same.  So I assume Qt is dumbed down to suit Mac
>  OSX, or maybe it is due to the extensive use of caches: fonts, images,
>  etc.

On X, all operations are serialised through the X connection socket. That's a 
shared resource, belonging to the entire application.

If multiple threads were writing to that socket, they'd need to coordinate to 
ensure that one thread does not step on the other one's toes. They must either 
lock the socket or execute only atomic writes -- which the POSIX API does not 
guarantee, so atomic writes are out.

Not to mention of course coordination between multiple operations and reading 
from the socket. Only one thread can read from the socket.

The alternative to that is to open one socket per thread. But libX11 doesn't 
do that and its API is also not thread-safe. I'm told libxcb can do it, but 
none of the major toolkits for X11 (Qt included) use it.

In any case, you're also right about the extensive use of caches and other 
resources. Since the Qt GUI API was designed to work in a single thread, it 
makes use of that fact to do lazy-initialisation, caching, etc. Some of the 
performance improvements introduced may require modifying a global state of 
some sort, which in turn would require locking if it were multithreaded.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- 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/20091020/3c1c3350/attachment.bin 


More information about the Qt-interest-old mailing list