QtConcurrent::run() starts a new thread after not being run for 30s
-
qDebug() << "called from Physical Thread ID: " << QThread::currentThreadId(); futureWatcher.setFuture(QtConcurrent::run([this]() { qDebug() << "Physical Thread ID: " << QThread::currentThreadId(); //some code }
I observed that this code consistently runs on the same thread if executed within 30 seconds of the last run. After this time threshold, it switches to a new thread. I discovered this behavior through console monitoring and a timer.
I want to know if this behavior could lead to issues, as I previously encountered a problem with thread exhaustion due to accidentally placing threads in an infinite loop. Why does this happen, and is there a way to disable this behavior to ensure that the futureWatcher doesn't switch threads every time it's called?
-
After 30 sec of inactivity the thread is killed to save resources.
-
@Christian-Ehrlicher Could you answer this please?
I want to know if this behavior could lead to issues, as I previously encountered a problem with thread exhaustion due to accidentally placing threads in an infinite loop. Is there a way to disable this behavior to ensure that the futureWatcher doesn't switch threads every time it's called?
-
@Grand_Titan I already have. The thread is cleaned up after a certain time of inactivity to save resources.