Results 1 to 2 of 2

Thread: Queued connection / Signal accumulation

  1. #1
    Join Date
    Jan 2008
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Queued connection / Signal accumulation

    I am writing a computer vision program and want to use multiple threads with event loops to process independant computation tasks at once.
    So its got this structre:


    Qt Code:
    1. ( Thread 1 ) ( Thread 2 ) __________
    2. _________ ___> | Module A1 |-->| Module A2 |-->| Module A3 |----->| Thread 4 |
    3. | Camera |____| | OpenGL |
    4. | Grabber| | | GUI |
    5. ---------- ---->| Module B1 | -->| Module B2|---------------------> -----------
    6. ( Thread 3 )
    To copy to clipboard, switch view to plain text mode 

    Thread 2 and 3 connect to the camera thread's signal newFrame(Image*) so they start processing their stuff independently.
    Thread 2 and 3 are also synchronized in such a way, that they only start to process a new fram if both of them finished their previous computation, otherwise thread 3 would process the next frame while thread 2 does not have the result yet and they become out of sync.

    Now the question! If all signals get queued, what happens if the threads take longer to process than the camera thread sends frames? Will they keep accumulating in the event queue and i will always lag behind the current frame? If the answer is yes, is there a way to dequeue or overwrite pending events with a more recent one?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Queued connection / Signal accumulation

    I think a better way is to make sure events are processed fast enough. Once you receive an event, store its data in some buffer. At that point you can decide to discard some lagging data. Then quickly return from the handler so that other events can be processed. Then use a timer that will be fetching frames at a specified frequency and process them there. Even if you get a lag, all "overflowing" events can discard their data (or some other data waiting to be processed) and everything should work. Just be sure to synchronize the buffer if you wish to use multiple threads for that.

  3. The following user says thank you to wysota for this useful post:

    pokey909 (23rd March 2008)

Similar Threads

  1. How to use Signal through direct connection
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2007, 07:07
  2. Signal and slot connection graph
    By fahlen in forum General Discussion
    Replies: 4
    Last Post: 27th November 2007, 13:47
  3. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 10:22
  4. signal slot connection
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 4th July 2006, 13:31
  5. queued signal/slot connection with QList<int>
    By smalls in forum Qt Programming
    Replies: 2
    Last Post: 7th February 2006, 14:32

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.