This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

What will happen if we remove the for(;;); from the main in the freeRTOS kernel??

Actually I read from the Mastering in the FreeRTOS documentation that,

/* If all is well then main() will never reach here as the scheduler will
now be running the tasks. If main() does reach here then it is likely that
there was insufficient heap memory available for the idle task to be created.
Chapter 2 provides more information on heap memory management. */
for( ;; );

what if I removed for( ;; ); from the main? I mean in case if anything happens in the project and if the control goes to that infinite loop then the product will hang forever.

So my question is why we use this?? can we remove it??

  • missing the required endless loop I expect that your program terminates within a sys_exit() (or similar) call

  • That's actually the wrong question.  Where exactly do you expect your program to go after it fell off the end of main()?  And how do you expect that result to be in any way, shape or form better than to be stuck in a well-defined endless loop?

  • lets say if we have code

    void main(void)
    {
    
    }

    at the end contains a return statement although we didn't explicitly put it there ourselves. When main returns the CPU executes the next instruction which is simply a GOTO to go back to the beginning of the code. main() is simply called over and over again. So why we preffer to stuck in while loop (at the end of the main) rather than calling main function again and again.

    Sir please can you elaborate what you are saying. I really want to clear this concept in my mind.

  • When main returns the CPU executes the next instruction which is simply a GOTO to go back to the beginning of the code.

    Do you just assume that happens, or did you look it up in some documentation about this tool chain?

  • I got the answer on the FreeRTOS forum

    What happens when you exit an embedded program is only defined by a particular implementation. Some may restart the program, but many just loop to stall. In any case, your program had a major failure where the system didn’t start up, and retrying is unlikely to change that. Ideally you want it easy to see what happened when debugging, so having the loop right there is helpfull.