# Any mandator rule that "voluteer yield" operation should or should not in critical section?

**URL:** <https://forums.freertos.org/t/any-mandator-rule-that-voluteer-yield-operation-should-or-should-not-in-critical-section/11943>\
**Category:** Kernel\
**Created:** [March 10, 2021, 9:11am UTC](https://forums.freertos.org/t/any-mandator-rule-that-voluteer-yield-operation-should-or-should-not-in-critical-section/11943 "2021-03-10T09:11:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tugouxp](https://avatars.discourse-cdn.com/v4/letter/t/f07891/32.png) [@tugouxp](https://forums.freertos.org/u/tugouxp)\
**Post date:** [March 10, 2021, 9:11am UTC](https://forums.freertos.org/t/any-mandator-rule-that-voluteer-yield-operation-should-or-should-not-in-critical-section/11943/1 "2021-03-10T09:11:30Z")

</div>

Hi folks:  
from the portyield call called positon,it seems there are no directly relationship for the vPortYield called with or without interrupt disabled.  
for example:  
taskYIELD\_IF\_USING\_PREEMPTION called in prvAddNewTaskToReadyList are with the EXIT CRITICAL was called before, this means the yield opeartion execution in preemptive context.  
but in many others cases, the taskYIELD\_IF\_USING\_PREEMPTION are called in critical section.

so this means, there is no a general principle that volunteer yield are held?  
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:** [March 10, 2021, 4:16pm UTC](https://forums.freertos.org/t/any-mandator-rule-that-voluteer-yield-operation-should-or-should-not-in-critical-section/11943/2 "2021-03-10T16:16:36Z")

</div>

As a general rule application code should [edit] NOT [/edit] yield from inside a critical section. That is in part because the behaviour of doing so will depend on the port you are using. Sometimes the yield will occur immediately (such as with ARMv4 architectures), sometimes the yield will occur when the critical section exits (such as with ARMv7 architectures). The FreeRTOS kernel does yield from inside critical sections but is designed to work in both cases (in the former case it has to save the critical section nesting depth and interrupt enable status as part of the task context).

---

<div class="post-metadata">

**Author:** ![tugouxp](https://avatars.discourse-cdn.com/v4/letter/t/f07891/32.png) [@tugouxp](https://forums.freertos.org/u/tugouxp)\
**Post date:** [March 11, 2021, 9:21am UTC](https://forums.freertos.org/t/any-mandator-rule-that-voluteer-yield-operation-should-or-should-not-in-critical-section/11943/3 "2021-03-11T09:21:22Z")

</div>

thank you very much!
