Global boolean vs EventGroup bit
Posted: Thu Jul 12, 2018 11:50 pm
I'm curious about the benefits of using EventGroup bits for event notification (not task synchronization) compared to a global. For example, task A can set a global boolean, which is checked by task B in a loop with task Delay:
compared to the following pattern:
Presumably the second version will return as soon as the bit is set so there could be a lower latency to detection. Are there other benefits?
TIA
Code: Select all
// task A sets the marker
bool marker;
function setMarker() {
marker = true;
}
// Task B checks the marker every second
while ( !marker ) {
vTaskDelay(1000);
};
Code: Select all
// task A sets the marker
extern EventGroupHandle_t events;
function setMarker() {
xEventGroupSetBits(events, 1);
}
// Task B blocks until this bit i set
xEventGroupWaitBits(events,1,pdFALSE,pdFALSE,portMAX_DELAY)
TIA