Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What about of the caller program after it call the function QtConcurrent::run()?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    isaacEnrique
    wrote on last edited by
    #1

    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.

    Isaac Pérez
    Programming is understanding.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      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

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • I Offline
        I Offline
        isaacEnrique
        wrote on last edited by
        #3

        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.

        Isaac Pérez
        Programming is understanding.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on last edited by
          #4

          Hi,

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

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved