[Interest] Qthread from QFuture?

Thiago Macieira thiago.macieira at intel.com
Wed Jan 5 13:31:13 CET 2022


On Tuesday, 4 January 2022 22:01:20 -03 Scott Bloom wrote:
> I appreciate the information.  However, I don’t understand why a QFuture
> created by QtConcurrent::run, if it can tell isRunning, why it cant return
> the QThread its using?

Because you don't have a use-case for using that pointer. What are you going 
to do with it, since you don't own that thread? First of all, it's also a race 
condition: the pointer may no longer be valid by the next instruction that you 
run.

It belongs to the thread pool you started the job on, and the thread pool may 
have more jobs to run. Obviously, the code that started that thread and is 
running jobs expects the job to cleanly exit (via exceptions or return, but 
still cleanly) so it can do its post-job maintenance on the thread and the job 
count. If you killed the thread, that thing will go completely out of sync and 
may crash or deadlock even harder.
 
> Unless there is simply no QThread, and its using all OS calls (which could
> make sense).
 
No, it's using QThread.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel DPG Cloud Engineering





More information about the Interest mailing list