# How do I notify a freeRTOS Task that a global variable or Mailbox has changed?

**URL:** <https://forums.freertos.org/t/how-do-i-notify-a-freertos-task-that-a-global-variable-or-mailbox-has-changed/15084>\
**Category:** Kernel\
**Created:** [May 16, 2022, 9:01pm UTC](https://forums.freertos.org/t/how-do-i-notify-a-freertos-task-that-a-global-variable-or-mailbox-has-changed/15084 "2022-05-16T21:01:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bitpatrol](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@bitpatrol](https://forums.freertos.org/u/bitpatrol)\
**Post date:** [May 16, 2022, 9:01pm UTC](https://forums.freertos.org/t/how-do-i-notify-a-freertos-task-that-a-global-variable-or-mailbox-has-changed/15084/1 "2022-05-16T21:01:57Z")

</div>

For my example, I have 3 tasks; UserInterfaceTask.c, WorkerTask.c and ControllerTask.c. When a user pushes a button the UserInterfaceTask detects it and sends a Queue message to the ControllerTask as a command with parameter and value. The ControllerTask then updates a global Mailbox which any tasks, including WorkerTask.c can access via xQueuePeek() however how do I notify the WorkerTask that a new value has been changed by ControllerTask using xQueueOverwrite()? My WorkerTask is polling, so is it acceptable to poll xQueuePeek() every 1 or 2ms or is there a cleaner way to be notified of changes to global variable or mailbox values?

Thank you!

---

<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:** [May 16, 2022, 10:20pm UTC](https://forums.freertos.org/t/how-do-i-notify-a-freertos-task-that-a-global-variable-or-mailbox-has-changed/15084/2 "2022-05-16T22:20:19Z")

</div>

For a task to get notified of an event immediately it needs to be blocked on whichever mechanism the event is sent through - otherwise it can only poll for the event, no matter what the event is. There isn’t an equivalent of a “signal” in unix, which is sort of a method of interrupting a thread.

---

<div class="post-metadata">

**Author:** ![bitpatrol](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@bitpatrol](https://forums.freertos.org/u/bitpatrol)\
**Post date:** [May 17, 2022, 1:58am UTC](https://forums.freertos.org/t/how-do-i-notify-a-freertos-task-that-a-global-variable-or-mailbox-has-changed/15084/3 "2022-05-17T01:58:21Z")

</div>

Ok, thanks for the info. I plan on using TaskNotify and setting TaskNotification value bits to flag two types of notifications. If it’s a ‘type=1’, than the receiving task will know to peek at mailbox values which have changed. If it’s a ‘type=2’, than the task will run it’s work. Is this a good approach or should I just use a Queue? I rather not incur the overhead queues bring.

Thanks!

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [May 17, 2022, 4:27am UTC](https://forums.freertos.org/t/how-do-i-notify-a-freertos-task-that-a-global-variable-or-mailbox-has-changed/15084/4 "2022-05-17T04:27:43Z")

</div>

Seems okay approach to me - since you are setting bits, just make sure to test bits (i.e. the value 3 may also be valid where both the notification are received before they are processed).

---

<div class="post-metadata">

**Author:** ![bitpatrol](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@bitpatrol](https://forums.freertos.org/u/bitpatrol)\
**Post date:** [May 17, 2022, 12:08pm UTC](https://forums.freertos.org/t/how-do-i-notify-a-freertos-task-that-a-global-variable-or-mailbox-has-changed/15084/5 "2022-05-17T12:08:27Z")

</div>

Ok, thanks, I’ll try this out today. In this case, I can use the bit flags as the ‘command byte’ of my communication protocol, and the mailbox as my ‘packet payload’, with no need to poll global variables. Thx.
