[Qt-interest] Can two thread share a QAbstractSocket?

Thiago Macieira thiago at kde.org
Wed May 12 19:12:45 CEST 2010


Em Quarta-feira 12. Maio 2010, às 18.35.51, Gabriele Kahlout escreveu:
> interesting. Why not?

Because QAbstractSocket will try to read from the socket as soon as there's 
something to be read, as well as try to write to it if there's anything 
buffered to be written. It does that by way of QSocketNotifier, which depends on 
the event loop.

So the notifiers always fire in the same thread. The buffers and internal state 
are not mutex-protected. If you try to use QAbstractSocket from two different 
threads (or more), you're going to have lots of data race-condition and it's 
going to either cause data loss or crash.
-- 
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: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100512/21705052/attachment.bin 


More information about the Qt-interest-old mailing list