[Qt-interest] problem using sockets and threads

pmqt71 pmqt71 at gmail.com
Tue Feb 8 23:47:00 CET 2011


Hi Thiago, thanks for your help.

First let me clarify that I'm using 1 thread per socket (not per
request) and only 1 consumer thread processing the requests from any
client/thread/socket.


> You probably have thread affinity errors. Your QTcpSocket classes are not affined
> with the threads where you're doing your reads and writes from.
>
RIGHT: I put a qDebug showing that readyRead runs in the main thread,
not in ClientConnectionThread. I'll try to use moveToThread.


>
>> 4) ConsumerThread gets the request from the queue, processes it and
>> answers to the client posting a custom event (having the answer as
>> data member) on the ClientConnectionThread
>
> On the thread class itself? Remember that the QThread object's thread affinity
> is to the thread that started it, not the thread it started. So the events are
> processed in that original thread.
>
> You should post the event to an object that is running in the thread, not to
> the thread.
>

Ok ok, posting events between threads is a MFC habit, but it seems to
work with Qt too!


>>
>> Is there something wrong (or all) in the design causing a problem in the
>> thread?
>
> Yes. In my opinion (opinion!), the design is completely wrong. You're using
> threads for sockets when you don't need to.
>

I'm using threads to parallelize IO operations over sockets, thinking
the app shoud handle clients over the internet, including mobiles with
slower connections. AFAIK in a single threaded socket app, a slow
client will degrade performances for all the clients.
Is Qt able to provide a kind of socket IO parallelism with no threads?

thanks
pm


>
>
> --
> 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
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
>



More information about the Qt-interest-old mailing list