How to deal with a cpu intensive thread


Hi, I have a really lengthy and cpu intensive code that currently runs in a separate thread. I inherit from ThreadWithProgressWindow, but because the threaded code uses calls to external libraries, whose running time I cannot control, I am unable to make regular checks on the threadShouldExit(). Plus the code is really lengthy and injecting the checks at various places makes it really ugly and unreadable.

I am considering to force the thread to exit, upon user request, instead of making a couple of dozens of checks and implement a cleanup function which should release allocated resources and related locks…

I don’t like forcing things to happen (it just feels wrong to me…), so any suggestions will be appreciated.

Note that this is my first encounter with JUCE and the solution to the above might be already implemented in it and I am just missing it.


You should NEVER kill a thread by force, either in juce or any other context. It’s simply not possible to safely kill a thread without polluting the app’s memory space. If the code you’re calling really can’t be stopped cooperatively, then you just have to leave it running! Or run it in a child process so you can kill the whole process.


Agreed and Noted :slight_smile: !

Thanks for the really quick response!