What about of the caller program after it call the function QtConcurrent::run()?



  • Regards.

    I have an application where I need to read data from a very large file and process them. Broadly speaking, the file consists of blocks of data that can be processed independently. Particularly, for processing, I have a function (void) receiving a raw block and is responsible for processing it.

    To speed up loading the file I want to overlap the calculation with reading, so that while a data block is processed you can go read the next block. Due to the characteristics of the multithread processing I have described, I think it is best to use <QtConcurrentRun> ... I will appreciate opinions about this option (pro or against).

    It's what I've tried, but in my first tests I have seen that the parallel program is slower (only slightly) than conventional (without threads).

    Now, reading the documentation again <QtConcurrentRun>, there is something not entirely clear to me (hence this post):

    What about of the caller program after it call the function QtConcurrent::run()?

    What the documentation says is that the function passed to QtConcurrent::run() is executed in another thread, but what about the caller: this stops to wait for the control of execution is returned to it (such as usually it happens when a function is invoked) or the caller continues its execution?

    Thanks in advance for any help and/or suggestions regarding this concern.



  • Hi,

    QtConcurrent::run() returns immediately a QFuture<T> object; if you're interested to know when the sub-thread finish you can use a QFutureWatcher and connect to its signals.

    Keep in mind that

    QFuture<T> QtConcurrent::run(Function function, ...)
    Runs function in a separate thread. The thread is taken from the global QThreadPool. Note that function may not run immediately; function will only be run once a thread becomes available.

    So be sure you have enough threads in the pool



  • Thanks for your answer.

    In that case How do I ensure that there are enough threads in the global QTheadPool ?. My call to QtConcurrent::run only passes the function name and four (4) parameters.



  • Hi,

    you can use QThreadPool::setMaxThreadCount() to change the maxThreadCount property.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.