Search code examples
multithreadingqtconcurrencyparallel-processingcancellation

Qt: How to cancel ALL processing of a QtConcurrent::map()?


I am using Qt5 on Windows7 platform.

In my current application I am using QtConcurrent to process all items in a container.
If I decide to exit the application, I am using: QFuture::cancel().
As per documentation http://doc.qt.io/qt-5/qfuture.html#cancel, not all async computations are canceled. Probably are canceled only the ones that are not yet started? And the running/ongoing computations are still allowed to continue to run?

If the above assumption is correct and QFuture::cancel() is not sufficient, then what should I do in order to stop also the running (ongoing) processing and exit the application gracefully?


Solution

  • You cannot pre-emptively and gracefully terminate asynchronous operations. The operations themselves must support co-operative cancellation.

    In other words, it's impossible for any framework, library, or operating system to provide this functionality for you. You must handle cancelling operations that have already started yourself.