0
0
FreeRTOSprogramming~5 mins

xTaskNotify() with value in FreeRTOS - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: xTaskNotify() with value
O(1)
Understanding Time Complexity

We want to understand how the time cost changes when using xTaskNotify() with a value in FreeRTOS.

Specifically, how does the execution time grow as the number of notifications or tasks changes?

Scenario Under Consideration

Analyze the time complexity of the following code snippet.


    BaseType_t xTaskNotify(
        TaskHandle_t xTaskToNotify,
        uint32_t ulValue,
        eNotifyAction eAction
    );
    

This function sends a notification with a value to a specific task, updating its notification state.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: Updating the notification value and checking the task state.
  • How many times: This happens once per call; no loops or recursion inside xTaskNotify().
How Execution Grows With Input

The execution time stays about the same no matter how many notifications are sent or how many tasks exist.

Input Size (n)Approx. Operations
10Constant steps to update one task
100Same constant steps for one task
1000Still constant steps for one task

Pattern observation: The time does not grow with input size; it stays constant.

Final Time Complexity

Time Complexity: O(1)

This means the time to notify a task with a value stays the same no matter how many tasks or notifications exist.

Common Mistake

[X] Wrong: "Notifying a task takes longer if many tasks exist or many notifications are sent."

[OK] Correct: The function targets one task directly and updates its notification value in constant time, so other tasks or notifications do not affect this time.

Interview Connect

Understanding that task notification functions run in constant time helps you reason about real-time system responsiveness and efficient task communication.

Self-Check

"What if xTaskNotify() was changed to notify multiple tasks at once? How would the time complexity change?"