Results 1 to 2 of 2

Thread: QtConcurrent Threads

  1. #1
    Join Date
    Jul 2010
    Posts
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question QtConcurrent Threads

    I'm using a QtConcurrent::run() thread for 20 threads that run at the same time as shown below. We have 20 network devices that run embedded Linux and this code loop fires a thread that uses LIBSSH2 to connect to each device and run some scripts. I'm also using Signals/Slots (not shown) to communicate status data between the main app and each Thread.

    My question is about how QtConcurrent uses threads. The documentation shows that each thread is taken from the global QThreadPool. In this class, there is a function that returns idealThreadCount() based on my processor. I'm wondering if it is recommended to use setMaxThreadCount() to set the Max Thread count to, say 5 or 10 if the idealThreadCount() returned is only 2? My 2.4GHz Centrino laptop (2GBram) returns a value of 2 for the idealThreadCount(). I've noticed that by setting this max value to 5 on my laptop causes my laptop to drag and the threads are just crawling but they are running.

    Just wondering if I should maybe limit the maximum thread count to less than or equal to the idealThreadCount() since I never know what type of PC the code will run on?? Or am I confusing this value? I certainly don't want a user's PC to come to a crawling standstill if I set the count too high to 20.

    Any suggestions?

    code snippet:
    for(int i = 0; i < 20; i++ )
    {
    QFuture<void> future = QtConcurrent::run(this, &QMainSubclassForm::MyThreadFunc,param1);
    m_FutureWatcher->setFuture(future);
    }

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QtConcurrent Threads

    The name of the function idealThreadCount() should really be amountOfCpuCores()

    It just returns the amount of cores on your pc. In your case 2.
    Obviously, you can run more threads than that.

    Of course, if each and every thread requires 100% cpu time, the amount of cores really becomes the ideal thread count.

Similar Threads

  1. QtConcurrent, i need advice
    By SABROG in forum Qt Programming
    Replies: 10
    Last Post: 29th December 2009, 20:53
  2. qtconcurrent
    By knishaq in forum Qt Programming
    Replies: 4
    Last Post: 15th December 2009, 09:41
  3. QtConcurrent question
    By bair in forum Qt Programming
    Replies: 5
    Last Post: 24th March 2009, 11:46
  4. QtConcurrent Performance
    By tomf in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2008, 16:41
  5. QtConcurrent
    By Brandybuck in forum An Introduction to QThreads
    Replies: 2
    Last Post: 9th May 2008, 15:10

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.