# Does "xSemaphoreGive" yield to the higher priority task 

**URL:** <https://forums.freertos.org/t/does-xsemaphoregive-yield-to-the-higher-priority-task/7374>\
**Category:** Kernel\
**Created:** [August 16, 2018, 2:15pm UTC](https://forums.freertos.org/t/does-xsemaphoregive-yield-to-the-higher-priority-task/7374 "2018-08-16T14:15:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 16, 2018, 2:15pm UTC](https://forums.freertos.org/t/does-xsemaphoregive-yield-to-the-higher-priority-task/7374/1 "2018-08-16T14:15:45Z")

</div>

**[unknowcoder](https://sourceforge.net/u/unknowcoder/)** wrote on [Thursday, August 16, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/ca6d3dc7/#3915):

I am having a weird case where when I give a semaphore the calling task does not yield.

**Test Case**

- I have two task A, B.
- Task A is the highest prioirty task, Task B is lower priority than A.
- Task A is pending on semaphore “X”.
- Task B gives semaphore “X”.
- I have preemption enabled

Given the test case I expect Task B to yield to Task A. As soon as semaphore “X” is given. But this doesn’t seem to be happening. Should I add task taskYIELD() asfter the semaphore is given? Is there anyway to check if the giving the semphore caused the task to yeild?

---

<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:** [August 16, 2018, 8:42pm UTC](https://forums.freertos.org/t/does-xsemaphoregive-yield-to-the-higher-priority-task/7374/2 "2018-08-16T20:42:04Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, August 16, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/ca6d3dc7/#3915/cdf2):

I’m not sure why you are observing that behaviour and suggest stepping  
into the semaphore ‘give’ function (which will map to a queue function)  
to see why. It should not be necessary to add in a taskYIELD().

---

<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:** [August 16, 2018, 8:42pm UTC](https://forums.freertos.org/t/does-xsemaphoregive-yield-to-the-higher-priority-task/7374/3 "2018-08-16T20:42:44Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, August 16, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/ca6d3dc7/#3915/b3cf):

Additionally - In my answer of a few moments ago I am assuming this is  
not being called from a critical section or with the scheduler suspended.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 20, 2018, 5:03pm UTC](https://forums.freertos.org/t/does-xsemaphoregive-yield-to-the-higher-priority-task/7374/4 "2018-08-20T17:03:00Z")

</div>

**[unknowcoder](https://sourceforge.net/u/unknowcoder/)** wrote on [Monday, August 20, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/ca6d3dc7/#b9b1):

I have solved it, it was interrupt related had nothing to do with the RTOS.  
Thanks
