How to stop Qt concurrent recursive run function from other thread?
I want to return from recursive function running in a separate thread from
some other thread.
I tried with Recursive mutex , but its not working !!
How can we achieve it ?
bool stop = false;
QMutex mutex(QMutex::Recursive);
int count = 1;
void worker_run () {
QMutexLocker locker(&mutex);
if(stop)
return;
qDebug () << count++;
worker_run();
}
void worker_stop () {
QMutexLocker locker(&mutex);
stop = true;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QtConcurrent::run(&worker_run);
QtConcurrent::run(&worker_stop);
return a.exec();
}
No comments:
Post a Comment