# Which API functions are available for use when scheduler is suspended using vTaskSuspendAll?

**URL:** <https://forums.freertos.org/t/which-api-functions-are-available-for-use-when-scheduler-is-suspended-using-vtasksuspendall/11759>\
**Category:** Kernel\
**Created:** [February 12, 2021, 4:50pm UTC](https://forums.freertos.org/t/which-api-functions-are-available-for-use-when-scheduler-is-suspended-using-vtasksuspendall/11759 "2021-02-12T16:50:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![adhikmewada](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/adhikmewada/32/1279_2.png) [@adhikmewada](https://forums.freertos.org/u/adhikmewada)\
**Post date:** [February 12, 2021, 4:50pm UTC](https://forums.freertos.org/t/which-api-functions-are-available-for-use-when-scheduler-is-suspended-using-vtasksuspendall/11759/1 "2021-02-12T16:50:57Z")

</div>

I want to use `xTaskGetTickCount` after calling `vTaskSuspendAll` when the scheduler is OFF. The documentation for `vTaskSuspendAll` function restricts calling of freertos API functions when the scheduler is suspended. But the `xTaskGetTickCount` function is simple and must be allowed for use.

Can someone help me know the API functions that are allowed to be used while the scheduler is OFF . . .

I want to make use of `xTaskGetTickCount` after calling `vTaskSuspendAll`.

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [February 12, 2021, 5:44pm UTC](https://forums.freertos.org/t/which-api-functions-are-available-for-use-when-scheduler-is-suspended-using-vtasksuspendall/11759/2 "2021-02-12T17:44:20Z")

</div>

It is too complex to list out the functions that can and can’t be used when the scheduler is suspended or from within a critical section - so there is a general rule of thumb that says don’t do it. The thing to really avoid is anything that could cause the calling task to block, that is always bad because if the scheduler is locked or the context switch interrupt’s can’t execute you will get a logic error - i.e. the calling task will continue running when it should be blocked waiting for an event. The next category of things to watch out for, but are less critical, is any function that unblocks another task - for similar reasons - although the errors you see will not necessarily be fatal as in the first case. In the case of xTaskGetTickCount(), the code is not doing anything other than returning a value, so it is ok to call with the scheduler suspended:  
[https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/V10.4.3/tasks.c#L2328](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/V10.4.3/tasks.c#L2328)

---

<div class="post-metadata">

**Author:** ![adhikmewada](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/adhikmewada/32/1279_2.png) [@adhikmewada](https://forums.freertos.org/u/adhikmewada)\
**Post date:** [February 19, 2021, 5:20am UTC](https://forums.freertos.org/t/which-api-functions-are-available-for-use-when-scheduler-is-suspended-using-vtasksuspendall/11759/3 "2021-02-19T05:20:15Z")

</div>

Thanks for the answer @rtel  
I’ll now be able to use of the `xTaskGetTickCount` function in the critical region.

Could you help me know if a function that unblocks other tasks is successful in marking it as unblocked in a crtical region? And whether the task will try to run only after the scheduler is resumed.

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [February 19, 2021, 9:15am UTC](https://forums.freertos.org/t/which-api-functions-are-available-for-use-when-scheduler-is-suspended-using-vtasksuspendall/11759/4 "2021-02-19T09:15:28Z")

</div>

It might be easier to know what else do you plan to do in a critical section.  
Usually the code in critical sections is kept as short as possible and is used to protected access to shared data.

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [February 19, 2021, 11:34pm UTC](https://forums.freertos.org/t/which-api-functions-are-available-for-use-when-scheduler-is-suspended-using-vtasksuspendall/11759/5 "2021-02-19T23:34:16Z")

</div>

> [@adhikmewada](#):
>
> Could you help me know if a function that unblocks other tasks is successful in marking it as unblocked in a crtical region? And whether the task will try to run only after the scheduler is resumed.

That is correct - the unblocked task will run when the next time scheduler runs. As @hs2 mentioned, knowing what you are trying to achieve may be useful to decide if you really need to unblock a task when the scheduler is suspended.

Thanks.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [February 19, 2021, 11:53pm UTC](https://forums.freertos.org/t/which-api-functions-are-available-for-use-when-scheduler-is-suspended-using-vtasksuspendall/11759/6 "2021-02-19T23:53:43Z")

</div>

A task that is unblocked when the scheduler is locked will start to run immediately the scheduler is unlocked - before the xTaskResumeAll() function returns. Assuming it has a priority above the currently running task of course.

Whether a task that is unblocked in a critical region executes immediately that the critical region is exited depends on the RTOS port. Ports that use asynchronous mechanism such as the Renesas RX or ARM Cortex port signal the requirement of a context switch by pending an interrupt - the handler for which will execute as soon as you leave the critical section. Ports that use a synchronous method, such as the ARM7 and ARM9 ports (not to be confused with the Cortex-M port which as an ARMv7M architecture) will not start to run the unblocked task until the scheduler runs again - worst case will be when the tick interrupt next executes.
