# Wake up multiple tasks with single IO event

**URL:** <https://forums.freertos.org/t/wake-up-multiple-tasks-with-single-io-event/9865>\
**Category:** Kernel\
**Created:** [May 24, 2020, 7:25pm UTC](https://forums.freertos.org/t/wake-up-multiple-tasks-with-single-io-event/9865 "2020-05-24T19:25:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ManuelOnFreeRTOS](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@ManuelOnFreeRTOS](https://forums.freertos.org/u/ManuelOnFreeRTOS)\
**Post date:** [May 24, 2020, 7:25pm UTC](https://forums.freertos.org/t/wake-up-multiple-tasks-with-single-io-event/9865/1 "2020-05-24T19:25:04Z")

</div>

Hello everyone,

I recently found out about FreeRTOS and been doing some experiments with it. I’m looking to make a “button” driver utilizing user buttons on the board I have.

Here’s the behavior I’m looking to implement:

- allow multiple tasks to block and wait for a button “event” to occur.
- once the button is pressed all tasks that were awaiting for the button press would be unblocked
- If a button event happens and afterwards a task queries the button driver for an event, the task would block and await a future button event. Button events only apply for tasks _already_ waiting for the event.

I’ve been looking into how to do it and I think using an event group is the way to go, but I just wanted to ask since I’m new to FreeRTOS.

Questions:

1. Is an event group the best way to go in order to implement the behavior I’m looking for?  
I’m looking to make this driver as simple and as lightweight as possible (it’s a silly little driver), so I’m looking to spend as little time as possible in kernel-space & avoid creating driver tasks/daemons.

2. My understanding is I don’t need to specify how many tasks are waiting for the same event group, is that correct?  
Ideally that’s what I want. I’m making a driver so I’d like my code to work with N tasks, although it’s not the end of the world if not.

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [May 24, 2020, 7:27pm UTC](https://forums.freertos.org/t/wake-up-multiple-tasks-with-single-io-event/9865/2 "2020-05-24T19:27:43Z")

</div>

Yes, An EventGroup is the way to handle multiple things waiting for a single ‘event’ to happen. When the event is posted to the group, EVERY task that was waiting in a way that the event is satisfied gets woken.

---

<div class="post-metadata">

**Author:** ![ManuelOnFreeRTOS](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@ManuelOnFreeRTOS](https://forums.freertos.org/u/ManuelOnFreeRTOS)\
**Post date:** [May 24, 2020, 7:31pm UTC](https://forums.freertos.org/t/wake-up-multiple-tasks-with-single-io-event/9865/3 "2020-05-24T19:31:36Z")

</div>

Thank you for clarifying Richard! I was 90% sure for that. My confusion mainly came from finding out about task notifications since the docs say it’s a lot more efficient to use, but it seems that it one can only notify a single task.

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [May 24, 2020, 8:44pm UTC](https://forums.freertos.org/t/wake-up-multiple-tasks-with-single-io-event/9865/4 "2020-05-24T20:44:15Z")

</div>

The Direct-to-Task notification system IS more efficient, largely because it only needs to handle waking up a single task, so it can be optimized for that. This removes a lot of resource contention.

If most of your events will only ever wake up a single task, and only occasionally do you need to wake up multiple tasks (but with a small upper limit for how many might be needed) you could replace the Event Group with a loop to signal each of the tasks with the direct-to-task system. I suspect that unless you are on the edge of your performance envelope, it won’t be worth the complexity.
