I'm facing a problem between where I need to keep my UI (and the full OS) responsive in multi-threaded application.
I'm developing an application (c++ and Qt based) which received and transform lot of video frame from multiple stream at the same time.
Each stream is retrieved, transformed and rendered in its own separate worker thread (using DirectX). That means I'm not using the default GUI thread to render the frame.
On a powerful computer I have no problem because the cpu can process all data and keep time for the GUI thread to process user request. But on a old computer, it doesn't work, the CPU is used at 100% to process my data, and UI is lagging, it may takes 10 seconds before a button click become processed.
I would like to keep my UI responsive. In fact, I want my worker thread works only if there is no others action to do. I tried to change the worker thread priority to low, but it doesn't work. I also tried a sleep(10) in the worker thread, but because I can have lots of threads, they don't fall in sleep at the same time, so it's not working either.
What is the best way to keep an UI responsive in that case (whatever the toolkit use)?
can't add my comments on above list so I've to add my few cents here:
One thing to check - how You do video display? Do you make sure your display rate (data from streams) matches display card's refresh rate? When You have data to display do You notify main thread about need to update screen (better solution) or You force frame display from each thread (bad solution)?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With