# Is it atomic TCB transfer from ready/pending lists?

**URL:** <https://forums.freertos.org/t/is-it-atomic-tcb-transfer-from-ready-pending-lists/17496>\
**Category:** Kernel\
**Tags:** debug\
**Created:** [May 25, 2023, 9:35am UTC](https://forums.freertos.org/t/is-it-atomic-tcb-transfer-from-ready-pending-lists/17496 "2023-05-25T09:35:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![smdbh](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/smdbh/32/3546_2.png) [@smdbh](https://forums.freertos.org/u/smdbh)\
**Post date:** [May 25, 2023, 9:35am UTC](https://forums.freertos.org/t/is-it-atomic-tcb-transfer-from-ready-pending-lists/17496/1 "2023-05-25T09:35:52Z")

</div>

is this a possible situation that may cause TCB losts?  
for a re-entry irq handler, if this operation is not atomic, it may cause a TCB removed from one list and not insert to new list, or bitmap not updated synchronized?

---

<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:** [May 25, 2023, 10:21am UTC](https://forums.freertos.org/t/is-it-atomic-tcb-transfer-from-ready-pending-lists/17496/2 "2023-05-25T10:21:41Z")

</div>

Kernel data, which includes task lists, is always updated in a critical section to ensure that the update is atomic. This avoids any inconsistent state as you described above. Are you facing any issue?

---

<div class="post-metadata">

**Author:** ![smdbh](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/smdbh/32/3546_2.png) [@smdbh](https://forums.freertos.org/u/smdbh)\
**Post date:** [May 25, 2023, 10:53am UTC](https://forums.freertos.org/t/is-it-atomic-tcb-transfer-from-ready-pending-lists/17496/3 "2023-05-25T10:53:13Z")

</div>

yes, i found a task will not be scheduled after running serveral minutes. I use jtag to debug the code and found this task is in pxReadyTasksLists but not in uxTopReadyPriority, after set the corresponding bit to 1, and continue run, this task back to normal.

i used gcc cr5 porting as reference, and i guess taskENTER\_CRITICAL() may not prevent higher priority irq re-entry since it just mask lower priority irqs.

currently, i try to use “cpsid/cpsie” to wrap " uxListRemove & prvAddTaskToReadyList operations", but not sure it completely solve the problem.

---

<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:** [May 25, 2023, 2:46pm UTC](https://forums.freertos.org/t/is-it-atomic-tcb-transfer-from-ready-pending-lists/17496/4 "2023-05-25T14:46:27Z")

</div>

> [@smdbh](#):
>
> i guess taskENTER\_CRITICAL() may not prevent higher priority irq re-entry since it just mask lower priority irqs.

But you are not supposed to call any FreeRTOS API from higher priority IRQs. Are you doing that? Also, see this response - [Understanding priority levels of ISR and FreeRTOS APIs - #16 by aggarg](https://forums.freertos.org/t/understanding-priority-levels-of-isr-and-freertos-apis/10453/16)

> [@smdbh](#):
>
> i used gcc cr5 porting as reference

Are you writing a new port? Which hardware is it?

---

<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:** [May 25, 2023, 4:25pm UTC](https://forums.freertos.org/t/is-it-atomic-tcb-transfer-from-ready-pending-lists/17496/5 "2023-05-25T16:25:59Z")

</div>

Please see this: [https://www.freertos.org/RTOS-ARM-Cortex-R5-Xilinx-UltraScale\_MPSoC.html#ConfigAndUsage](https://www.freertos.org/RTOS-ARM-Cortex-R5-Xilinx-UltraScale_MPSoC.html#ConfigAndUsage)

---

<div class="post-metadata">

**Author:** ![smdbh](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/smdbh/32/3546_2.png) [@smdbh](https://forums.freertos.org/u/smdbh)\
**Post date:** [May 26, 2023, 9:10am UTC](https://forums.freertos.org/t/is-it-atomic-tcb-transfer-from-ready-pending-lists/17496/6 "2023-05-26T09:10:55Z")

</div>

thanks for your suggustion. i guess the problem may cause by interrupt prio settings.

for cortex R5, is systick timer irq priority MUST lower than configMAX\_API\_CALL\_INTERRUPT\_PRIORITY, or any suggestion value? currently, mine is 16, bigger than defaut 18. timer irq may run during xEventGroupSetBitsFromISR() function, the mask-irq protection is not effective now.

so , timer tick irq should always be lowest priority?

---

<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:** [May 26, 2023, 9:12am UTC](https://forums.freertos.org/t/is-it-atomic-tcb-transfer-from-ready-pending-lists/17496/7 "2023-05-26T09:12:40Z")

</div>

> [@smdbh](#):
>
> so , timer tick irq should always be lowest priority?

Not necessarily the lowest but it has to be less than or equal to configMAX\_API\_CALL\_INTERRUPT\_PRIORITY.
