What happens when external functions are interrupted?

Hey guys,
i’m trying to learn about RTOS right now, but i’ m still at the beginning.

My goal is to convert an already existing program into a RTOS.
I have the following question: What happens if I call an “external” function of this program from a task A, but the task is interrupted by a task B with a higher priority.

I can imagine the following scenarios:

  1. the execution of the external function simply breaks off in the middle, if task A continues, the function starts again or the next step in task A is executed
  2. the current progress of the function execution is stored in the same way as for a task, once task A proceeds again the program continues at this point

I am grateful for any input, my research in the interent was not very successful.


There really isn’t anything like an ‘external function’, but Task A is the function given, and all the functions called by that function, for that particular invocation of create task (a given function may be part of many different tasks)

1 Like

… and with Richard’s explanation the 2. scenario is (kind of) right.
There are systems where a scenario similar to 1. might apply for example an interrupted system call on Linux with separate kernel and user space. But it’s not exactly the same.
This doesn’t apply to systems like FreeRTOS without such a separation and often it’s not even desirable.

1 Like

First of all I would like to thank you for the quick answers!

I have to admit that I don’t quite understand what @richard-damon is trying to tell me (which could be because English is not my mother tongue).

According to @hs2 my second assumption seems to be correct, but to be on the safe side I try to formulate my question more clearly:

At the moment task A is running. Within this task a function is called, which is completely outside of the RTOS, so it is not connected to any task. Let’s say the execution of the function reaches line 10.
Now task B is started, because it has a higher priority.
Now the question is what happens when task A has the highest priority again? Is line 11 of the function is executed, does the function restart from line 1 or is the next line in task A executed (so function is not executed to the end).

I hope this makes my question a bit clearer :slight_smile:

Richard tried to explain that calling a function like say printf from a running task A makes no difference. It’s nothing special, it’s still code executed in the context or by task A.
There is no such thing as an external function from the RTOS point of view.
What happens is that the code of task A is continued exactly at the processor instruction where it was interrupted by the scheduler. Regardless which code of which C function is currently executed. It doesn’t matter. All happens at a lower (machine) level.
Tasks just continue to run seamlessly. You don’t need to take care about that.

1 Like

Now I got it, thank you very much!