# Broadcast event to multiple tasks

**URL:** <https://forums.freertos.org/t/broadcast-event-to-multiple-tasks/7969>\
**Category:** Kernel\
**Created:** [July 18, 2019, 11:49am UTC](https://forums.freertos.org/t/broadcast-event-to-multiple-tasks/7969 "2019-07-18T11:49:33Z")\
**Posts on this page:** 6\
**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:** [July 18, 2019, 11:49am UTC](https://forums.freertos.org/t/broadcast-event-to-multiple-tasks/7969/1 "2019-07-18T11:49:33Z")

</div>

**[g8aryan](https://sourceforge.net/u/g8aryan/)** wrote on [Thursday, July 18, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/9c09bf3f4f/#8439):

I am trying to set a event from a task(Z). There are three task(A, B, C) waiting for the same event.

In case the priority of the task(Z) whcih sets the event is lower than the tasks(A, B, C) waiting for the event the events for fine and all the task gets unblocked.  
But in case the priority of all the tasks(Task(Z) setting the event and Tasks(A, B, C) waiting for the event) is same, then only one Task(A) gets unblocked and remaining Tasks(B, C) remain in blocked state.

Why is it?

To simplyfy i created only four tasks(Z, A, B, C) and one event group and start the scheduler.  
The task(Z) that sets the event does not perform any other functionality other than setting the events.  
And the tasks(A, B, C) waiting for the event also does not perform any functionality other than waiting for the event.

Anyone knows the reason?

---

<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:** [July 18, 2019, 2:05pm UTC](https://forums.freertos.org/t/broadcast-event-to-multiple-tasks/7969/2 "2019-07-18T14:05:47Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, July 18, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/9c09bf3f4f/#8439/7f78):

How do you determine that the tasks do not get unblocked. What is  
configUSE\_TIME\_SLICING set to in FreeRTOSConfig.h - wondering if the  
implementation is just not allowing the other tasks to execute.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 21, 2019, 7:27am UTC](https://forums.freertos.org/t/broadcast-event-to-multiple-tasks/7969/3 "2019-07-21T07:27:59Z")

</div>

**[g8aryan](https://sourceforge.net/u/g8aryan/)** wrote on [Sunday, July 21, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/9c09bf3f4f/#f4de):

Hi Richard,

The configUSE\_TIME\_SLICING is set to 1.

I have gpios which in toggle in every task.  
My task implementation is as below: -  
static void SetTask(void \*pvParameters)  
{  
EventBits\_t SetBit;  
uint8\_t Gpio = \*((uint8\_t \*)pvParameters);

```
for(; ; )
{
    SetGpio(Gpio);
    SetBit = xEventGroupSetBits(SetWaitEvt, 1);
    ClearGpio(Gpio);
}

```

}

static void WaitTask1(void \*pvParameters)  
{  
EventBits\_t WaitBit1;  
uint8\_t Gpio = \*((uint8\_t \*)pvParameters);

```
for(; ; )
{
    SetGpio(Gpio);
    WaitBit1 = xEventGroupWaitBits(SetWaitEvt, 1, pdTRUE, pdTRUE, portMAX_DELAY);
    ClearGpio(Gpio);
}

```

}

static void WaitTask2(void \*pvParameters)  
{  
EventBits\_t WaitBit2;  
uint8\_t Gpio = \*((uint8\_t \*)pvParameters);

```
for(; ; )
{
    SetGpio(Gpio);
    WaitBit2 = xEventGroupWaitBits(SetWaitEvt, 1, pdTRUE, pdTRUE, portMAX_DELAY);
    ClearGpio(Gpio);
}

```

}  
static void WaitTask3(void \*pvParameters)  
{  
EventBits\_t WaitBit3;  
uint8\_t Gpio = \*((uint8\_t \*)pvParameters);

```
for(; ; )
{
    SetGpio(Gpio);
    WaitBit3 = xEventGroupWaitBits(SetWaitEvt, 1, pdTRUE, pdTRUE, portMAX_DELAY);
    ClearGpio(Gpio);
}

```

}

---

<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:** [July 21, 2019, 11:05am UTC](https://forums.freertos.org/t/broadcast-event-to-multiple-tasks/7969/4 "2019-07-21T11:05:25Z")

</div>

**[richard\_damon](https://sourceforge.net/u/richard_damon/)** wrote on [Sunday, July 21, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/9c09bf3f4f/#43f4):

At a quick look at your tasks, SetTask never blocks for anything, and thus totally starves any lower priority tasks and tasks of the same priority only get time based on the round robin scheduling, which isn’t designed to be perfect.

Try adding a vTaskDelay call in SetTask to limit how fast it runs.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 21, 2019, 2:35pm UTC](https://forums.freertos.org/t/broadcast-event-to-multiple-tasks/7969/5 "2019-07-21T14:35:49Z")

</div>

**[g8aryan](https://sourceforge.net/u/g8aryan/)** wrote on [Sunday, July 21, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/9c09bf3f4f/#5b59):

Hi Richard,

I tried with vTaskDelay as well, but the result is same.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [July 21, 2019, 7:14pm UTC](https://forums.freertos.org/t/broadcast-event-to-multiple-tasks/7969/6 "2019-07-21T19:14:48Z")

</div>

**[richarddamon](https://sourceforge.net/u/richarddamon/)** wrote on [Sunday, July 21, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/9c09bf3f4f/#6249):

About all I can say is that for me, a single xEventGroupSetBits call will put all the tasks currently pending on a matching xEventGroupWaitBits call back to the ready state, and as long as I give them a chance to get CPU time will run.
