Yes, dividing into subtasks or doing sth similar is probably the easiest way to go in most cases but it's not always possible, especially when talking about legacy code. And lets say we have sth like this then:
void slot_myAlgorithm()
{
// spawns thread and joins at its end
if(!runSubtask1())
showError();
if(!runSubtask2())
showError();
if(!runSubtask3())
showError();
}
void slot_myAlgorithm()
{
// spawns thread and joins at its end
if(!runSubtask1())
showError();
if(!runSubtask2())
showError();
if(!runSubtask3())
showError();
}
To copy to clipboard, switch view to plain text mode
What if another developer wants to reuse this entire algorithm pipeline from inside another thread? Then he again runs into this threading trouble and either has to restructure or copy existing code both of which should be avoided imo.
And as another example: What if I'm using an std::thread which requires a static run function where I can't emit any signals from because it's not a QObject?
Bookmarks