Results 1 to 4 of 4

Thread: Multithreading

  1. #1
    Join Date
    Feb 2014
    Posts
    7

    Default Multithreading

    Hi guys,

    i would like to ask you something.

    I am getting data over TCP/IP, the processing of this data is done in one thread.

    The next step would be the processing of this data like plot etc. but i would like not to
    desturb the TCP thread.

    My opportunities could be:

    - To use the lock.read() method but in this way i would block the TCP thread.
    - I could send the data with signal slot connection, but if i get an update every ms i would block the main thread.

    - To send data data with UDP to 127.0.0.1

    What do you think ? Any ideas ?

    Regards

  2. #2
    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: Multithreading

    You will likely want a combination of the classic producer/consumer queue and notifying the consumer instead of letting it poll.

    So something like:
    - a properly synchronized queue into which the producer addes and from which the consumer takes
    - producer sending a signal when it adds new work and the queue was empty

    Cheers,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    7

    Default Re: Multithreading

    thats the reason why i thought about UDP...

    or can you show me an example what you mean?

  4. #4
    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: Multithreading

    Quote Originally Posted by JS27 View Post
    thats the reason why i thought about UDP...
    While sending data to yourself via loopback network would potentially work, why go through all the trouble and overhead?

    Quote Originally Posted by JS27 View Post
    or can you show me an example what you mean?
    Well, assuming your data is a type "Data", you would have a container or queue
    Qt Code:
    1. QQueue<Data> data;
    To copy to clipboard, switch view to plain text mode 
    that both thread's have access to, obviously using QMutex to do that in an orderly fashion.

    Then the worker thread would have a signal that it emits when the queue is empty when it adds something new and connect that to a slot in the main thread.
    In the slot you can then either take all the data or process it in batches.
    When you've cleared the queue you know that you will get notified again if there is new data.

    Cheers,
    _

Similar Threads

  1. Multithreading & GUI
    By qthread in forum Qt Programming
    Replies: 22
    Last Post: 24th August 2014, 10:37
  2. Multithreading
    By havij000 in forum Newbie
    Replies: 22
    Last Post: 21st August 2013, 13:35
  3. When to use Multithreading?
    By "BumbleBee" in forum General Programming
    Replies: 5
    Last Post: 30th April 2011, 18:21
  4. regarding multithreading
    By mohanakrishnan in forum Qt Programming
    Replies: 19
    Last Post: 9th December 2009, 08:21
  5. multithreading
    By mickey in forum General Programming
    Replies: 2
    Last Post: 5th June 2008, 22:01

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.