Task function signature in FreeRTOS - Time & Space Complexity
We want to understand how the time it takes to run a FreeRTOS task function changes as the task runs.
Specifically, we ask: How does the task function's execution time grow with its input or workload?
Analyze the time complexity of the following FreeRTOS task function signature and its loop.
void vTaskFunction(void *pvParameters) {
for(;;) {
// Task code here
}
}
This code defines a task function that runs forever in a loop, doing some work repeatedly.
Look for loops or repeated actions inside the task function.
- Primary operation: The infinite
for(;;)loop repeats the task's work. - How many times: It runs endlessly, repeating the task code over and over.
The task runs continuously, so the total execution time grows indefinitely as it keeps running.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | Runs 10 times through the loop |
| 100 | Runs 100 times through the loop |
| 1000 | Runs 1000 times through the loop |
Pattern observation: The number of operations grows linearly with how many times the loop runs.
Time Complexity: O(n)
This means the time spent grows directly with the number of loop iterations the task performs.
[X] Wrong: "The task function runs once and then stops, so time is constant."
[OK] Correct: The task function has an infinite loop, so it keeps running repeatedly, making time grow with the number of iterations.
Understanding how task functions run repeatedly helps you explain how embedded systems handle ongoing work efficiently.
"What if the task function had a delay inside the loop? How would that affect the time complexity?"