@JKSH said in Function not always returning if called in thread???:
Your code has race conditions. You must protect data/objects that are accessed by multiple threads: https://en.wikipedia.org/wiki/Race_condition#Software
Hey, that's very informative link! Thats fully explains what happening during execution of my func. Thanks.
It's good to know again, that Earth spinning around the Sun, gravity pulls things down and programs does'nt run forward until they finish execution of the function.
Result:
At the first i invented some upgrade, added second (predefined)parameter:
static void reportToConsole(QString msg, int pause=0)
{
tBrowPtr->append("<font color=\"#808080\">"+currentTime()+
":</font color>"+msg);
if(pause!=0) Sleep(pause);
}
I could specify some amout of mSecs to wait, if func used in my Thread loop.
Works well, but then i read that stuff @JKSH posted, and realized that even specifying 20 or even 30 msecs - not guaranteeing safe execution. App simply could be running at old slow PC, and those mSecs amount might not be enough.
So i creating simple "another" function which connects MainWindow and Worker, so error send from the worker will be executed in MainWindow SLOT. Like in old days...
Now the only tiny thing left - how can i forbid Workers thread use my global common function instead of emiting Signal. Could accidentally, call wrong reportToConsole)