Generally our application has one “main” task which create others tasks. “Main” task is inside C++ “main” class. So I noticed that changing TerminateProcess
is good because destructors will be called. But as I mentioned application didn’t finished itself.
So my first solution was that I call TerminateProcess
when “main” task is deleted (deletion of the task I have in destructor of my “main” class) inside* vPortCloseRunningThread* instead of ExitThread
. But there is disadvantage of this solution that when task wants to be finished by itself during standard operation TerminateProcess
is executed and application finished.
After davidefer replied to my post then I tried the proposition. I removed exit(0)
and signaled scheduler to finish endless loop (and enabled interrupt so scheduler could be called). Then my application can reach return
statement in main function in main thread and destructors also will be called (even for objects outside of my “main” task). So this solutions sound even better.
Unfortunately there are still some threads which are not finished and application still exist. Strange thing is when application reach main there are 4 threads already. I’m not sure if it has anything in common in affinity (which is set to 1 core further).
Next I took @davidefer port.c from
and result is still the same.
So I still call TerminateProcess
which is executed because pxCurrentTCB
was not changed and it keeps “main” task (the task trigger process termination). The whole thing is called in “main” class destructor which is called at the end of my application. I know the solution is not elegant but it works 🙂
@davidefer -> one remark to termination of threads at the end of schedule. I think in
for (int i=0; i< createdThreadsNum; i++)
ulErrorCode = TerminateThread(createdThreadsList[i].pvThread, 0);
configASSERT should be removed since tasks can be finished dynamically during operation and TerminateThread can return 0. I think the best it to ignore it and try with next one.
Thanks for support, I'm still open for updates, suggestions, tips.