# Wait for multiple notifications before continuing Task

**URL:** <https://forums.freertos.org/t/wait-for-multiple-notifications-before-continuing-task/14551>\
**Category:** Kernel\
**Created:** [February 25, 2022, 12:15pm UTC](https://forums.freertos.org/t/wait-for-multiple-notifications-before-continuing-task/14551 "2022-02-25T12:15:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![willESP32](https://avatars.discourse-cdn.com/v4/letter/w/ce73a5/32.png) [@willESP32](https://forums.freertos.org/u/willESP32)\
**Post date:** [February 25, 2022, 12:15pm UTC](https://forums.freertos.org/t/wait-for-multiple-notifications-before-continuing-task/14551/1 "2022-02-25T12:15:02Z")

</div>

I have 3 tasks - taskA, taskB and taskC.

I need taskA to waits for both taskB and taskC to finish before continuing.

I am trying to use FreeRTOS’ notifications for this but unsure how to use xTaskNotifyWait to wait for not one notification but two before reseting notifications and carrying on with taskA.

My current idea is this:

```auto
    //Task B
    xTaskNotify(taskA, (1<<0), eSetBits); // set 0th bit HIGH
    // Task C
    xTaskNotify(taskB, (1<<1), eSetBits); // set 1st bit HIGH

    // Task A
    while(ulNotifiedValue != 5)
    {
      xTaskNotifyWait(0, 0, &ulNotifiedValue, (TickType_t)portMAX_DELAY);
    }
    // reset notification value
    ulNotifiedValue = 0
    // contiunue with taskA...

```

However, this seems to block at xTaskNotifyWait indefinitely.

Any help much appreciated,  
Will

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [February 25, 2022, 12:40pm UTC](https://forums.freertos.org/t/wait-for-multiple-notifications-before-continuing-task/14551/2 "2022-02-25T12:40:29Z")

</div>

> [@willESP32](#):
>
> `while(ulNotifiedValue != 5)`

`b1|b0 = 1|1 == 3` right 😉  
Could be easily found by yourself watching `ulNotifiedValue ` with a debugger or some log output.

---

<div class="post-metadata">

**Author:** ![willESP32](https://avatars.discourse-cdn.com/v4/letter/w/ce73a5/32.png) [@willESP32](https://forums.freertos.org/u/willESP32)\
**Post date:** [February 25, 2022, 2:03pm UTC](https://forums.freertos.org/t/wait-for-multiple-notifications-before-continuing-task/14551/3 "2022-02-25T14:03:49Z")

</div>

Ah dear it’s been a long week.  
Unsure how clean this method is but it seems to work now.  
Thanks

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [February 25, 2022, 2:41pm UTC](https://forums.freertos.org/t/wait-for-multiple-notifications-before-continuing-task/14551/4 "2022-02-25T14:41:20Z")

</div>

😄 … The method is just fine.  
You surely have a `ulTaskNotifyValueClear` somewhere for the next signaling sequence.

---

<div class="post-metadata">

**Author:** ![willESP32](https://avatars.discourse-cdn.com/v4/letter/w/ce73a5/32.png) [@willESP32](https://forums.freertos.org/u/willESP32)\
**Post date:** [February 25, 2022, 4:06pm UTC](https://forums.freertos.org/t/wait-for-multiple-notifications-before-continuing-task/14551/5 "2022-02-25T16:06:08Z")

</div>

Ah I thought ` ulNotifiedValue = 0` would do the trick but I think you’re right.  
Sadly `ulTaskNotifyValueClear ` is not available on ESP32 currently, so will have to try and update library.

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [February 25, 2022, 5:46pm UTC](https://forums.freertos.org/t/wait-for-multiple-notifications-before-continuing-task/14551/6 "2022-02-25T17:46:02Z")

</div>

Alternatively you could assemble/collect the bits in a local variable and set the `ulBitsToClearOnExit` argument of `xTaskNotifyWait` to the complete bitmask (3).

```auto
static uint32_t const BitMask = 3;
uint32_t ulNotifiedBits = 0, ulNotifiedValue = 0;
while( ulNotifiedBits != BitMask )
{
    xTaskNotifyWait(0, BitMask, &ulNotifiedValue, (TickType_t)portMAX_DELAY);
    ulNotifiedBits |= ulNotifiedValue;
}

```
