Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Multi Threading, pause and resume?
Jeroi last edited by
Since I don't seem to find proper knowledge either on google or in IRC I tought to start this discussion in very interesting topic. Since we all want threading when doing paraller work. But what about threads that takes long time. Some time you want to pause your thread to watch HD movie or some similar case.
I first taught QRunnable. I subclassed it and tought well I can have signal and slots to control one boolean variable and my worker checks that boolean in every loop that is it paused then start somekind of eternal loop.
How ever further more studied I became aware that signals and slots are not available with QRunnable so I looked about QThread. And here is atm the situation.
I have this first suggestion code for my worker class atm: http://stackoverflow.com/questions/9075837/pause-and-resume-a-qthread
Since one guy over Qt irc channel told me a crazy if I try using QMutex and QWaitCondition to cause pause state and I started to believe that the crazyness might be thing with QWaitCondition::resumeAll() that might interfere another threads going aswell. This even tho QWaitCondition is privately announced for the worker thread.
So I searched another methods and it seams QtConcurrent support signals and slot somewhat and has pause and resume built in it looks nice, but don't find any good example yet for it.
So could someone teach me how to to multitasking with correct method to pause and resume?
It really depends on what you want to do in the other thread, and how you've structured your program.
I recommend you start by reading "Multithreading Technologies in Qt":http://doc-snapshot.qt-project.org/qt5-release/threads-technologies.html -- it compares all the different ways to use threads in Qt.
If your program can use the map/filter/reduce pattern, Qt Concurrent provides pause/resume functionality.
[quote author="Jeroi" date="1400188871"]Since I don't seem to find proper knowledge either on google or in IRC[/quote]Did you check Qt's official documentation?