Results 1 to 10 of 10

Thread: Overhead when transmitting same signal to multiple threads via QueuedConnection

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Overhead when transmitting same signal to multiple threads via QueuedConnection

    1. Who performs connect: sender or receiver ?
    2. Who decides whether to ignore data: sender or receiver ?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,233
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Overhead when transmitting same signal to multiple threads via QueuedConnection

    If I now copy the payload needlessly to many threads (all but one discard the message), I create an unnecessary overhead.
    You are passing your QJsonObject instance by value: sendData( QJsonObject o ). In C++, this requires making a copy of the data. If you pass by reference instead: sendData( QJsonObject & o ) or sendData( const QJsonObject & o ) if the object will not be modified during the call, then you avoid copying.

    And as Lesiok asks, if you are in control of the connections, then why are you making connections to receivers who ignore the signal?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Overhead when transmitting same signal to multiple threads via QueuedConnection

    Quote Originally Posted by d_stranz View Post
    if the object will not be modified during the call, then you avoid copying.
    In general this is true, but not in the case of a QueuedConnection.

    That mechanism requires that the signal arguments are stored in QVariant as the event being used for the delayed/cross-thread invocation uses that to store the arguments of the call.

    However, if we look at QJsonOject's copy constructor we see that it uses reference counting instead of copying the data itself.

    Which of course also means that none of the threads, including the main thread, should attempt any modification of the object as it is now shared data.

    Cheers,
    _

  4. The following 2 users say thank you to anda_skoa for this useful post:

    d_stranz (17th January 2019), ghorwin (18th January 2019)

Similar Threads

  1. QNetworkAccessManager in multiple threads
    By mentalmushroom in forum Qt Programming
    Replies: 2
    Last Post: 7th August 2013, 23:14
  2. Qt socket consumes memory after transmitting
    By marco.stanzani in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2012, 11:38
  3. Signal-Signal Connections Between Threads
    By PhilippB in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2008, 18:27
  4. Waiting for multiple threads
    By Bebee in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2008, 17:21
  5. QueuedConnection's and threads
    By gri in forum Qt Programming
    Replies: 14
    Last Post: 24th January 2007, 09:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.