Which statement best explains why design patterns improve reliability in FreeRTOS multi-tasking?
Think about how design patterns help organize code and manage shared resources.
Design patterns offer proven ways to handle common problems like synchronization and resource conflicts, which are critical for reliable multi-tasking in FreeRTOS.
What is the output of this FreeRTOS code snippet that uses a binary semaphore to synchronize two tasks?
SemaphoreHandle_t xSemaphore;
void Task1(void *pvParameters) {
xSemaphoreTake(xSemaphore, portMAX_DELAY);
printf("Task1 running\n");
xSemaphoreGive(xSemaphore);
vTaskDelete(NULL);
}
void Task2(void *pvParameters) {
printf("Task2 running\n");
xSemaphoreGive(xSemaphore);
vTaskDelete(NULL);
}
int main() {
xSemaphore = xSemaphoreCreateBinary();
xTaskCreate(Task1, "Task1", 1000, NULL, 1, NULL);
xTaskCreate(Task2, "Task2", 1000, NULL, 1, NULL);
vTaskStartScheduler();
return 0;
}Consider which task gives the semaphore and which waits for it.
Task2 prints first and gives the semaphore. Task1 waits for the semaphore, then runs after Task2.
Given two tasks that each wait for a semaphore held by the other, what is the cause of the deadlock?
SemaphoreHandle_t sem1, sem2;
void TaskA(void *pvParameters) {
xSemaphoreTake(sem1, portMAX_DELAY);
vTaskDelay(10);
xSemaphoreTake(sem2, portMAX_DELAY);
// ...
}
void TaskB(void *pvParameters) {
xSemaphoreTake(sem2, portMAX_DELAY);
vTaskDelay(10);
xSemaphoreTake(sem1, portMAX_DELAY);
// ...
}Think about what happens when two tasks wait on each other's resources.
Each task holds one semaphore and waits for the other, so neither can proceed, causing deadlock.
Which option contains the correct syntax to create a FreeRTOS task?
void vTaskCode(void *pvParameters) {
for(;;) {
// Task code
}
}Check the function pointer and string syntax.
Option A correctly passes the function pointer and task name as a string literal.
You need to design a FreeRTOS system where multiple producer tasks send data to a single consumer task safely and efficiently. Which design pattern is best suited for this scenario?
Think about how to safely pass data between tasks without conflicts.
Message queues allow multiple producers to send data safely to a consumer, handling synchronization and buffering.