Results 1 to 8 of 8

Thread: consuming thread usage.

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default consuming thread usage.

    Hi friends,

    Im working in a networking project with GUI ..

    This is my scenario ..
    Im receiving two different data say server1, server2,

    server 1 running as udp so to receive i use one QThread thread1,
    server 2 running as Multicast so to receive i use one QThread thread2

    and i need to map the both value and perform some calculation so i used another seperate thread thread3 to receive both the data simultaneously without interupping GUI ..

    is there any other good way as i can conserve the usage of thread .. ?
    any other stuff like QConcurrent or other things i can deploy in later ..?


    Please help me

    Thanks in advance ..
    "Behind every great fortune lies a crime" - Balzac

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: consuming thread usage.

    You can not use threads at all. The GUI thread is enough to do all the tasks.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: consuming thread usage.

    Is you question about how to avoid threads?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  4. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: consuming thread usage.

    Quote Originally Posted by wysota View Post
    You can not use threads at all. The GUI thread is enough to do all the tasks.
    first thanks for the reply wysota
    but how i can receive two different data at a same time in a loop .. from server one and two synchronously ... and display those two datas in a table ..

    Quote Originally Posted by Santosh Reddy View Post
    Is you question about how to avoid threads?
    Thanks for the reply reddy ..
    yes ..
    i want to reduce the thread usage ...
    "Behind every great fortune lies a crime" - Balzac

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: consuming thread usage.

    Quote Originally Posted by wagmare View Post
    but how i can receive two different data at a same time in a loop .. from server one and two synchronously ... and display those two datas in a table ..
    Use signals and slots. You don't need any loops. When one socket signals it has data ready, read it, store it, check if the other socket already received the data you need and if not then return. Do the same for the other socket. If both sockets already received their data, emit a signal that both are ready and in a slot connected to that signal read the stored data and process it. The latter can be done in an external thread (e.g. using QtConcurrent::run()) if processing is computation intensive.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    wagmare (4th February 2013)

  7. #6
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: consuming thread usage.

    The latter can be done in an external thread (e.g. using QtConcurrent::run()) if processing is computation intensive
    Thx wysota ..
    yes .. the computation is intense ..
    Can u explain me why i should go for QConcurrent ..specifically ..and not normal QThread::run() ..?
    "Behind every great fortune lies a crime" - Balzac

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: consuming thread usage.

    There are several reasons. If the computation can be enclosed in a single function then using Qt Concurrent is like calling that single function where you can pass arguments directly and obtain a deferred result through the use of QFuture. With QFutureWatcher you can be notified when the computation is complete. Furthermore Qt Concurrent will spawn only as many threads as there are cores available which allows to handle a situation where data bursts in faster than it can be processed. With a regular QThread You would have to either spawna a new thread for each incoming data which is a straight way to DOS or you would have to queue requests and synchronise the thread. In short if you can use Qt Concurrent, it is usually easier than implementing your own thread.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    wagmare (4th February 2013)

  10. #8
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: consuming thread usage.

    Well explained ... thank you Wysota ..
    "Behind every great fortune lies a crime" - Balzac

Similar Threads

  1. Replies: 1
    Last Post: 25th October 2012, 15:10
  2. How time consuming is a d-pointer access?
    By pospiech in forum Qt Programming
    Replies: 3
    Last Post: 8th June 2010, 09:54
  3. Application consuming 60% of CPU usage ..
    By wagmare in forum Qt Programming
    Replies: 3
    Last Post: 20th October 2009, 10:23
  4. Once again: buttons and time consuming tasks
    By pampo in forum Qt Programming
    Replies: 1
    Last Post: 4th May 2009, 18:26
  5. Show progress of a time consuming operation
    By rainman110 in forum Newbie
    Replies: 7
    Last Post: 10th February 2008, 12:07

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.