# xSemaphoreGiveFromISR from context of a task

**URL:** <https://forums.freertos.org/t/xsemaphoregivefromisr-from-context-of-a-task/698>\
**Category:** Kernel\
**Created:** [March 20, 2009, 12:30pm UTC](https://forums.freertos.org/t/xsemaphoregivefromisr-from-context-of-a-task/698 "2009-03-20T12:30:36Z")\
**Posts on this page:** 2\
**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:** [March 20, 2009, 12:30pm UTC](https://forums.freertos.org/t/xsemaphoregivefromisr-from-context-of-a-task/698/1 "2009-03-20T12:30:36Z")

</div>

**[jstoezel](https://sourceforge.net/u/jstoezel/)** wrote on [Friday, March 20, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/1cb67bf4/#b69e):

Hi,

Sorry if this post appears twice, my first attempt seems to have failed.

I need to write that piece of code that is generic enough that it allows giving a semaphore from the context of either an ISR or a task. Since an ISR must use xSemaphoreGiveFromISR to give semaphores, is it possible to use xSemaphoreGiveFromISR in the context of a task?

If so, any cons with doing this?

Jean

---

<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 20, 2009, 2:46pm UTC](https://forums.freertos.org/t/xsemaphoregivefromisr-from-context-of-a-task/698/2 "2009-03-20T14:46:19Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, March 20, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/1cb67bf4/#b69e/204a):

You can use xQueueGenericSendFromISR() from a task but need to take care of critical sections.&nbsp; The ISR version uses portSET\_INTERRUPT\_MASK\_FROM\_ISR() which is only defined for ports that use interrupt nesting.&nbsp; You would need to implement an equivalent for your port if it were not already defined.

Regards.
