Results 1 to 7 of 7

Thread: QFutureWatcher and "cancel" on a QtConcurrent filter...

  1. #1
    Join Date
    Dec 2013
    Posts
    14
    Thanks
    2
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QFutureWatcher and "cancel" on a QtConcurrent filter...

    ... is it save to replace the future of a watcher right after calling "cancel" on the watcher?

    i.e.:
    Qt Code:
    1. m_watcher.cancel();
    2.  
    3. ProcessWrapper process;
    4. m_watcher.setFuture(QtConcurrent::filter(m_cacheQueue, process));
    To copy to clipboard, switch view to plain text mode 
    i have no particular use for the future returned by the concurrent filter, so i just simply set it to the watcher; also i don't connect the watcher signals, which only purpose is to cancel processing and immediately start processing a new sequence; the docs say that cancel is async, what'd be the preferred way in this case as i don't want to wait for the (now obsolete) previous processing results. i just wonder what happens internally if i do this that way from the outside it looks ok, and everything seems to work as expected...

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: QFutureWatcher and "cancel" on a QtConcurrent filter...

    You can cancel a future directly, you don't need a watcher for this.
    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
    Dec 2013
    Posts
    14
    Thanks
    2
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QFutureWatcher and "cancel" on a QtConcurrent filter...

    Quote Originally Posted by wysota View Post
    You can cancel a future directly, you don't need a watcher for this.
    thanks!

    i forgot to add that i also decided to use a watcher because this seems to be the easiest way to also have throttling - so the original question remains.
    if the method above (call cancel on the watcher and immediately set a new future) could cause problems, i'll probably drop the watcher, and implement throttling by a QSemaphore. another way would be to re-use the watcher with a new future and cancel the previous future afterwards.

    another question in this regards: the docs state that a QFuture is reference counted, but what does that mean to the lifetime of i.e. a QFuture object returned by QtConcurrent? does adding and removing a future to/from a watcher (the way i do it above) trigger reference counting, and would that mean that the future is destroyed when it is removed from the (last) watcher, even if it is still working? somehow i don't get a clear view on this by what the docs say...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: QFutureWatcher and "cancel" on a QtConcurrent filter...

    Quote Originally Posted by t_3 View Post
    thanks!

    i forgot to add that i also decided to use a watcher because this seems to be the easiest way to also have throttling - so the original question remains.
    The only thing a watcher adds to QFuture is the ability to emit signals, nothing else.

    another question in this regards: the docs state that a QFuture is reference counted, but what does that mean to the lifetime of i.e. a QFuture object returned by QtConcurrent?
    It means that if you copy the future and destroy the original, the copy retains the personality of the original. Thus if you set a future on a watcher (copy) and destroy the original one, the future still functions in the watcher. "Reference counting" is nothing unique to Qt, just STFW for this term.
    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.


  5. #5
    Join Date
    Dec 2013
    Posts
    14
    Thanks
    2
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QFutureWatcher and "cancel" on a QtConcurrent filter...

    Quote Originally Posted by wysota View Post
    The only thing a watcher adds to QFuture is the ability to emit signals, nothing else.
    thanks again... but...

    "The setPendingResultsLimit() provides throttling control. When the number of pending resultReadyAt() or resultsReadyAt() signals exceeds the limit, the computation represented by the future will be throttled automatically. The computation will resume once the number of pending signals drops below the limit."

    as this method is only available through the watcher but not the future itself, the statement from the docs is either wrong or i did badly misinterpret it? i also read it in a way it doesn't matter if the (any) signals are connected at all?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: QFutureWatcher and "cancel" on a QtConcurrent filter...

    If you do not connect any signals from the watcher tthen I don't see how throttling is of any use to you. It makes sense only if the producer is faster than the consumer for really large data sets where resource consumption matters. If you are not processing entries as they appear in the result (which would require the use of signals) then if throttling kicked in your operation would never complete.

    Maybe you should describe what you are trying to achieve with QtConcurrent, why you need throttling and how you process the results.
    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.


  7. #7
    Join Date
    Dec 2013
    Posts
    14
    Thanks
    2
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QFutureWatcher and "cancel" on a QtConcurrent filter...

    Quote Originally Posted by wysota View Post
    If you do not connect any signals from the watcher tthen I don't see how throttling is of any use to you. It makes sense only if the producer is faster than the consumer for really large data sets where resource consumption matters. If you are not processing entries as they appear in the result (which would require the use of signals) then if throttling kicked in your operation would never complete.

    Maybe you should describe what you are trying to achieve with QtConcurrent, why you need throttling and how you process the results.
    i process [some of the] future results in the main/ui thread, but for particular reasons i'm using own signals instead of the watcher ones.

    i work on a plugin that needs to access two different, both non thread safe api's (one from a Qt based host application, and external other one), so whenever i like to offload processing to keep the ui responsive it gets complicated, not the last because i have only very limited control - for example the threadpool threads limit; in this particular case the thread limit is already way beyond what is healthy for the particular modules task (thumbnails rendering on a gpu), so i need a way to limit concurrent processing on my own.

    the key part in the docs description is the wording "pending signals". i of course see that to calculate a "pending" number (to test against a limit) needs something that adds and removes signals from a "pending" list (however that works). means you are probably right that watcher throttling won't work if i don't use the internal methods to consume results. after some test it seems that the setting has just no effect at all in this case - even if i set the limit to "1" the filter still runs down the sequence without being ever paused... so i'm going to use a semaphore.

    thanks for your help...

Similar Threads

  1. Proper handling "Cancel" click for QWizard
    By Splinter in forum Qt Programming
    Replies: 4
    Last Post: 17th September 2012, 14:34
  2. Replies: 3
    Last Post: 8th December 2011, 19:21
  3. Replies: 3
    Last Post: 15th February 2010, 17:27
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. Replies: 11
    Last Post: 10th July 2007, 15:58

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.