# Block task until an event happens (xTaskNotify didn't fit)

**URL:** <https://forums.freertos.org/t/block-task-until-an-event-happens-xtasknotify-didnt-fit/38>\
**Category:** Kernel\
**Created:** [November 16, 2015, 2:42pm UTC](https://forums.freertos.org/t/block-task-until-an-event-happens-xtasknotify-didnt-fit/38 "2015-11-16T14:42:11Z")\
**Posts on this page:** 5\
**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:** [November 16, 2015, 2:42pm UTC](https://forums.freertos.org/t/block-task-until-an-event-happens-xtasknotify-didnt-fit/38/1 "2015-11-16T14:42:11Z")

</div>

**[gutolaureano](https://sourceforge.net/u/gutolaureano/)** wrote on [Monday, November 16, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/0485b1e0/#7af8):

Hello,

I would like some help to find out how use the FreeRTOS resources:

I need lock a task execution until an event (interrupt) happen, but i need unlock the task only if this event happened after the task has been locked, interrupts that happened before the lock does not care, the first feature that came in mind was the task Notify events, but I figured out that if any event happened before the xTaskNotifyWait it will not lock (because the state will be eNotified) even if I set all bits in ulBitsToClearOnEntry  
( is there a way to clean the eNotified state before calling xTaskNotifyWait() ?)

Stopping the interrupt until the locking moment is not an option, any suggestions?  
(I am new to the RTOS world, still learning how to model my solutions using RTOS, sorry if this is a trivial problem)

Thanks for your time!  
Gustavo

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 16, 2015, 3:05pm UTC](https://forums.freertos.org/t/block-task-until-an-event-happens-xtasknotify-didnt-fit/38/2 "2015-11-16T15:05:03Z")

</div>

**[davedoors](https://sourceforge.net/u/davedoors/)** wrote on [Monday, November 16, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/0485b1e0/#adda):

You can call xTaskNotifyWait() with a block time of 0 to clear the notification state before you call it again to wait for the interrupt. In 8.2.3 there is also a function xTaskNotifyStateClear().

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 16, 2015, 3:36pm UTC](https://forums.freertos.org/t/block-task-until-an-event-happens-xtasknotify-didnt-fit/38/3 "2015-11-16T15:36:07Z")

</div>

**[gutolaureano](https://sourceforge.net/u/gutolaureano/)** wrote on [Monday, November 16, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/0485b1e0/#37fa):

Thank you!  
Exactly what I needed!

I’m using 8.2.1 atm, I can just update my Freertos source to the latest? no need any adittional changes, right?

Thanks again

---

<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:** [November 16, 2015, 3:41pm UTC](https://forums.freertos.org/t/block-task-until-an-event-happens-xtasknotify-didnt-fit/38/4 "2015-11-16T15:41:13Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, November 16, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/0485b1e0/#37fa/e3fb):

Yes - it should be just a drop in replacement.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 17, 2015, 3:59pm UTC](https://forums.freertos.org/t/block-task-until-an-event-happens-xtasknotify-didnt-fit/38/5 "2015-11-17T15:59:02Z")

</div>

**[gutolaureano](https://sourceforge.net/u/gutolaureano/)** wrote on [Tuesday, November 17, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/0485b1e0/#6be7):

Perfect!  
Thanks
