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. QtConcurrent using Sequence generated on-the-fly

QtConcurrent using Sequence generated on-the-fly

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 935 Views 1 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.
  • A Offline
    A Offline
    AlexPo
    wrote on last edited by
    #1

    Documentation and all examples I've seen assume that "Sequence ":http://qt-project.org/doc/qt-5/qtconcurrent.html#mapped (e.g. QList, QVector, etc.) is given in advance. That is, we know how many mapFunction() calls (and its' parameters) there will be beforehead.

    Problem I am faced with is that new items that need to be proceded might emerge during the execution of QtConcurrent::mapped(). How can it be acheived?

    I had an idea to inherit QFuture::const_iterator, override operators and use QtConcurrent::mapped(ConstIterator, ConstIterator, MapFunction) with ConstIterator being inherited class. Is it a good approach?

    1 Reply Last reply
    0
    • JKSHJ Online
      JKSHJ Online
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      [quote author="AlexPo" date="1389308650"]Documentation and all examples I've seen assume that "Sequence ":http://qt-project.org/doc/qt-5/qtconcurrent.html#mapped (e.g. QList, QVector, etc.) is given in advance. That is, we know how many mapFunction() calls (and its' parameters) there will be in advance.[/quote]Yes, that is a fundamental assumption of the map/filter/reduce functions. Your container is expected to remain the same size at all times.

      [quote]Problem I am faced with is that new items that need to be proceed might emerge *during * the execution of QtConcurrent::mapped(). How can it beforehead?[/quote]Would it be possible to do your processing in batches?

      i.e. Call mapped() for a fixed-sized container. If any new items emerge, collect them in a new container. Then, run mapped() again. Repeat until there are no more new items.

      [quote]I had an idea to inherit QFuture::const_iterator, override operators and use QtConcurrent::mapped(ConstIterator, ConstIterator, MapFunction) with ConstIterator being inherited class. Is it a good approach?[/quote]I wouldn't. For one thing, you will chang the meaning of const, and break the assumptions that Qt Concurrent makes.

      Another possible approach is to subclass QRunnable instead. Create a QRunnable for each item to be processed. You can add new QRunnables to the thread pool on-the-fly. You can collect results by adding them to a mutex-protected shared container.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AlexPo
        wrote on last edited by
        #3

        Thanks for reply!

        [quote author="JKSH" date="1389316006"]Would it be possible to do your processing in batches?

        i.e. Call mapped() for a fixed-sized container. If any new items emerge, collect them in a new container. Then, run mapped() again. Repeat until there are no more new items.
        [/quote]

        Yes, it would. But in my case that would be rather ugly design.

        [quote author="JKSH" date="1389316006"]I wouldn't. For one thing, you will chang the meaning of const, and break the assumptions that Qt Concurrent makes.

        Another possible approach is to subclass QRunnable instead. Create a QRunnable for each item to be processed. You can add new QRunnables to the thread pool on-the-fly. You can collect results by adding them to a mutex-protected shared container.[/quote]

        I see. QRunnable then. Thanks again!

        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